How to get high price of the last candle of the last session?

I want to compare current candle price against price High of the last candle of the last session.

So if we are in Day 2 at 9:02 or at 10:14 I want to compare against Day 1 at 20:00 (suppose that is the last 1minute candle of the day).

I know I can do easily if I am looking for closing price:

last_day_close_price = TimeFrameGetPrice( "Close", inDaily, -1);

But how do I do if I want the last high value of the candle?

Thanks,

/// @link https://forum.amibroker.com/t/how-to-get-high-price-of-the-last-candle-of-the-last-session/8345/2
SetBarsRequired(86400/Max(1,Interval()));

if( Interval() >= inDaily )
	Error( "SET TO INTRADAY INTERVAL !" );

dn = Datenum();
start_of_day = dn != Ref(dn,-1);
hh = ValueWhen( start_of_day, Ref(H,-1));
printf( "High of Last Bar of previous Day: %g", hh );

Plot( C, "Price", colorDefault, styleBar );
Plot( hh, "High of Last Bar of previous Day", colorGreen, styleNoRescale );

_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} - {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%), Vol %g {{VALUES}}",
                           O, H, L, C, SelectedValue( ROC( C, 1 ) ), V ) );
4 Likes

Thanks, not only addresses the problem but also let me learn other AFL stuff.

I have noticed that the above code will give the high value of the last candle of the day (as requested) and that it is consistent with the selected timeframe -i.e., if we are in 1h the high used will be the one of the last 1h candle of the last session-.

What if I always want to have the reference of the last 1min candle of the last session, no matter what timeframe is the chart on? Note: my goal is to have an indicator which gives you the opening gap against low and high values of the last 1min candle of the previous session.

Read how Timeframes work in AB.
You will not be able to access a TF lower than currently what is defined in the Chart.

You have to build your code around the TF that you are working on, so one can use a 1m chart and plot on higher TF but not vice-versa.

Read This
https://www.amibroker.com/guide/h_timeframe.html

PLEASE NOTE that you can only compress data from shorter interval to longer interval. So when working with 1-minute data you can compress to 2, 3, 4, 5, 6, ....N-minute data. But when working with 15 minute data you can not get 1-minute data bars. In a similar way if you have only EOD data you can not access intraday time frames.