{"id":1086,"date":"2015-02-02T16:32:34","date_gmt":"2015-02-02T21:32:34","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/?p=1086"},"modified":"2015-02-11T18:37:21","modified_gmt":"2015-02-11T23:37:21","slug":"high-low-of-certain-hours-of-the-day","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2015\/02\/02\/high-low-of-certain-hours-of-the-day\/","title":{"rendered":"High-Low of certain hours of the day"},"content":{"rendered":"

When we want to calculate high \/ low of selected hours of the trading session (e.g. first two trading hours), we can refer to TimeNum() function to identify timestamps of the bars. Then with use of HighestSince<\/strong> and ValueWhen<\/strong> functions we can obtain the high\/low readings we need.<\/p>tn <\/span>= <\/span>TimeNum<\/span>();

<\/span>\/\/ define start\/end hours in TimeNum format
<\/span>StartTime <\/span>= <\/span>93000<\/span>;
<\/span>Endtime <\/span>= <\/span>113000<\/span>;

<\/span>\/\/ these conditions are true when TimeNum of the bar equals startime\/endtime
<\/span>StartBar <\/span>= <\/span>tn <\/span>== <\/span>StartTime<\/span>;
<\/span>EndBar <\/span>= <\/span>tn <\/span>== <\/span>Endtime<\/span>;

<\/span>\/\/ on the end bar we read the value of highest high or lowest low since the start bar
<\/span>myH <\/span>= <\/span>ValueWhen<\/span>( <\/span>EndBar<\/span>, <\/span>HighestSince<\/span>( <\/span>StartBar<\/span>, <\/span>High <\/span>) );
<\/span>myL <\/span>= <\/span>ValueWhen<\/span>( <\/span>EndBar<\/span>, <\/span>LowestSince<\/span>( <\/span>StartBar<\/span>, <\/span>Low <\/span>) );

<\/span>\/\/ display price and high \/ low arrays
<\/span>Plot<\/span>( <\/span>Close<\/span>, <\/span>"Close"<\/span>, <\/span>colorDefault<\/span>, <\/span>styleBar<\/span>|<\/span>styleThick <\/span>);
<\/span>Plot<\/span>( <\/span>myH<\/span>, <\/span>"myH"<\/span>, <\/span>colorGreen<\/span>, <\/span>styleThick <\/span>);
<\/span>Plot<\/span>( <\/span>myL<\/span>, <\/span>"myL"<\/span>, <\/span>colorRed<\/span>, <\/span>styleThick <\/span>);

<\/span>\/\/ grey lines show how highest high \/ lowest low develop since start bar
<\/span>Plot<\/span>( <\/span>HighestSince<\/span>( <\/span>StartBar<\/span>, <\/span>High <\/span>), <\/span>""<\/span>, <\/span>colorgrey50 <\/span>);
<\/span>Plot<\/span>( <\/span>LowestSince<\/span>( <\/span>StartBar<\/span>, <\/span>Low <\/span>), <\/span>""<\/span>, <\/span>colorgrey50 <\/span>);

<\/span>\/\/ area chart shows the zone we are reading our values from
<\/span>Plot<\/span>( <\/span>tn <\/span>>= <\/span>StartTime <\/span>AND <\/span>tn <\/span><= <\/span>Endtime<\/span>, <\/span>""<\/span>
      <\/span>ColorBlend<\/span>( <\/span>colorYellow<\/span>, <\/span>colorWhite<\/span>, <\/span>0.9 <\/span>), 
      <\/span>styleArea <\/span>| <\/span>styleOwnScale<\/span>, <\/span>0<\/span>, <\/span>1<\/span>, <\/span>0<\/span>, -<\/span>1<\/span>)<\/code>

\"H-L<\/p>

Now we can use myH and myL arrays in strategies that e.g. check for breakouts from the first two hours of trading session etc.<\/p>

It is important to remember that the code checks for equality, so the timestamps used in our charts must exactly match the time we specify in the code. The timestamp settings can be defined in Tools->Preferences->Intraday<\/strong>. The approach presented above uses 1-minute data and timestamps showing Start Time of Interval<\/strong><\/p>","protected":false},"excerpt":{"rendered":"

When we want to calculate high \/ low of selected hours of the trading session (e.g. first two trading hours), we can refer to TimeNum() function to identify timestamps of the bars. Then with use of HighestSince and ValueWhen functions we can obtain the high\/low readings we need.tn = TimeNum();\/\/ define start\/end hours in TimeNum formatStartTime = 93000;Endtime = 113000;\/\/ these conditions are true when TimeNum of the bar equals startime\/endtimeStartBar = tn == StartTime;EndBar = tn == Endtime;\/\/ on the end bar we read the value of highest high or lowest low since the start barmyH = ValueWhen( EndBar, HighestSince( StartBar, High ) );myL = ValueWhen( EndBar, LowestSince( StartBar, Low ) );\/\/ display price and high \/ low arraysPlot( Close, "Close", colorDefault, styleBar|styleThick );Plot( myH, "myH", colorGreen, styleThick );Plot( myL, "myL", colorRed, styleThick );\/\/ grey lines show how highest high \/ lowest low develop since start barPlot( HighestSince( StartBar, High ), "", colorgrey50 );Plot( LowestSince( StartBar, Low ), "", colorgrey50 );\/\/ area chart shows the zone we are reading our values fromPlot( tn >= StartTime AND tn <= Endtime, "",       ColorBlend( colorYellow, colorWhite, 0.9 ),       styleArea | styleOwnScale, 0, 1, 0, -1)Now we can use myH and myL arrays […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1086"}],"collection":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/comments?post=1086"}],"version-history":[{"count":1,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1086\/revisions"}],"predecessor-version":[{"id":1088,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1086\/revisions\/1088"}],"wp:attachment":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/media?parent=1086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/categories?post=1086"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/tags?post=1086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}