I've asked something similar before, but this one goes another level down, and now I don't know if I can accomplish this without a loop. This comes from a much more complex piece of code that I've reduced for example's sake here. I'm hoping there is a way to do this without using a loop because it will get real complex if that is required.
I need to disqualify this sequence (denoted by the horiztonal, aqua, small circles) when we either hit the top channel, or Max(X bars after the first aqua circles start, Y bars after the second aqua circles start). So, what is confusing me is that I need information about the second level's barcount to disqualify the first level. But since the second level is built upon the first level, I don't have that information at the top of the code, which is where I need it to disqualify.
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
dt = DateTimeToStr(GetCursorXPosition());
bi = BarIndex();
myMA = MA(close, 22);
myATR = ATR(20);
Level1 = myMA - 1 * myATR;
TopLevel = myMA + 1 * myATR;
Plot(myMA,"myMA",colorWhite,styleLine);
Plot(Level1,"Level1",colorWhite,styleDashed);
Plot(TopLevel,"Level1",colorWhite,styleDashed);
ResetCondition = High >= ref( TopLevel, -1 );
Setup1Condition = Low <= Ref(Level1, -1);
Flip1 = Flip( Setup1Condition, ResetCondition );
Level1PotentialPrice = Min(Open, ref( Level1, -1 ));
Level1Price = ValueWhen( Flip1 == 1 AND Ref(Flip1, -1) == 0, Ref(Level1PotentialPrice,0));
PlotShapes(IIf(Flip1 == 1, shapeSmallCircle, shapeNone),colorAqua, 0, Level1Price, Offset=0);
Level2 = Level1Price - myATR * 1;
Setup2Condition = Low <= Ref(Level2, -1);
Flip2 = Flip( Setup2Condition, ResetCondition );
Level2PotentialPrice = Min(Open, ref( Level2, -1 ));
Level2Price = ValueWhen( Flip2 == 1 AND Ref(Flip2, -1) == 0, Ref(Level2PotentialPrice,0));
PlotShapes(IIf(Flip2 == 1, shapeSmallCircle, shapeNone),colorAqua, 0, Level2Price, Offset=0);
Level1BarsSince = BarsSince(Flip1 AND Ref(Flip1, -1) == 0);
Level2BarsSince = BarsSince(Flip2 AND Ref(Flip2, -1) == 0);
PlotShapes(IIf( (Ref(Flip1,-1) OR Ref(Flip2,-1)) AND ResetCondition, shapeCircle, shapeNone),colorWhite, 0, Max(ref( TopLevel, -1 ), Open), Offset=0);
BarsSinceDisqualifyCondition = ( ( Flip1 AND Ref(Flip1,-1) AND BarsSince(Flip1 AND Ref(flip1,-1) == 0) == 20 ) OR ( Flip2 AND Ref(Flip2,-1) AND Max( BarsSince(Flip1 AND Ref(flip1,-1) == 0) == 20, BarsSince(Flip2 AND Ref(flip2,-1) == 0) == 10 ) ) );
PlotShapes(IIf(BarsSinceDisqualifyCondition, shapeCircle, shapeNone),colorWhite, 0, Close , Offset=0);
So, I need both cyan horizontal dots to stop being drawn, which I am considering that to be the disqualification of the whole sequence, where the hand drawn line blue vertical line is drawn.
How do I get the information about Level2 up there to disqualify Level1 without using a loop?