Fix required for AmiBroker AFL for ORB

I am trying this following code to use it as an overlay for opening range breakout. The issue is that apart from the current session, it is also plotting last two sessions. But I don’t need that. How can I fix this issue? Below is the code -

_SECTION_BEGIN("Intraday ORB");

BT = ParamTime ("Open Breakout Time", "09:15");
afterbreakout0 = Cross(TimeNum(),BT);
afterbreakout1 = TimeNum()>=BT;
NewDay = Day()!= Ref(Day(), -1);
highestoftheday = HighestSince(newday,H,1);
Lowestoftheday =LowestSince(newday,L,1);
ORBH = ValueWhen(afterbreakout0,highestoftheday,1);
ORBL = ValueWhen(afterbreakout0,lowestoftheday,1);
ORBM = (ORBH + ORBL)/2;

Plot(ValueWhen(NewDay, LastValue(ORBH, True), 1),"",colorGreen,styleDots | styleThick);
Plot(ValueWhen(NewDay, LastValue(ORBL, True), 1),"",colorRed,styleDots | styleThick);
Plot(ValueWhen(NewDay, LastValue(ORBM, True), 1),"", colorBlack, styleDots | styleThick);
_SECTION_END();

Thanks for your time and effort in advance. Regards.

Add this to your code

today = Day() == LastValue(Day());

// use this instead of your plot()
Plot( IIf(today, LastValue(ORBH, True), Null),"",colorGreen,styleDots | styleThick);

Then modify the same in ORBL and ORBM

1 Like

Works great. Thanks a lot again. I have also uploaded the stochastic AFL for the fix necessary on Histogram. Lets hope you can solve that too. Regards.