amibroker

HomeKnowledge Base

High-Low of certain hours of the day

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 format
StartTime 93000;
Endtime 113000;

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

// on the end bar we read the value of highest high or lowest low since the start bar
myH ValueWhenEndBarHighestSinceStartBarHigh ) );
myL ValueWhenEndBarLowestSinceStartBarLow ) );

// display price and high / low arrays
PlotClose"Close"colorDefaultstyleBar|styleThick );
PlotmyH"myH"colorGreenstyleThick );
PlotmyL"myL"colorRedstyleThick );

// grey lines show how highest high / lowest low develop since start bar
PlotHighestSinceStartBarHigh ), ""colorgrey50 );
PlotLowestSinceStartBarLow ), ""colorgrey50 );

// area chart shows the zone we are reading our values from
Plottn >= StartTime AND tn <= Endtime""
      
ColorBlendcolorYellowcolorWhite0.9 ), 
      
styleArea styleOwnScale010, -1);

H-L from selected hours

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.

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. The approach presented above uses 1-minute data and timestamps showing Start Time of Interval

Comments are closed.