Hi everyone,
I'm trying to build an AFL that will Capture the high and low of the first 5-minute candle of the day (at 9:15 AM) and then display those values on the chart - even when I'm viewing a higher timeframe (like 15-min, 30-min, etc.).
Here’s what I want to achieve:
- The logic should detect the first 5-minute bar of the day.
- Store that bar’s High and Low values (only once per day).
- Display the stored values as text (using
GfxTextOut
) - The values must stay accurate even if I switch to a non-5-minute chart (like 15-min).
Below is the code I’ve tried. Unfortunately, it returns the high and low of the first candle of the day based on the current chart timeframe, rather than the actual 5-minute candle values I need.
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
_SECTION_BEGIN("X & Y Coordinates");
Title = " ";
td = 1.2;
td1 = 1.0;
x=Param("xposn",1,0,1000,1);
y=Param("yposn",1,0,1000,1);
_SECTION_END();
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
TimeFrameSet(in5Minute);
fb = Day()!=Ref(Day(), -1);
val_5MinHigh = ValueWhen(fb, High);
val_5MinLow = ValueWhen(fb, Low);
TimeFrameRestore();
GfxTextOut( "5Min High:"+TimeFrameExpand(val_5MinHigh, in5Minute), x+10, y+80 );
GfxTextOut( "5Min Low:"+TimeFrameExpand(val_5MinLow, in5Minute), x+10, y+120 );
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
Plot( C, "Close", Colorred, styleCandle | styleThick | styleDots);
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
Any help or working example would be greatly appreciated!
Thanks in advance!