Consider the below code.
_TRACE( "!CLEAR!" );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}} ", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
SetChartOptions( 0, chartShowArrows | chartShowDates | chartWrapTitle );
PlotOHLC( O, H, L, C, "Close", colorRed, styleBar , Null, Null, 0, 1, 1 );
patternFound=Ref(HHV(H, 10), -1)<H;
PlotShapes( IIF( patternFound, shapesmallSquare , shapeNone ), colorYellow, 0, L );
TenBarsAheadOfPatternFound=BarsSince(patternFound)==10;
highOfPreviousPatternFound=ValueWhen(patternFound, H);
atr5=ATR(5);
PlotShapes( IIF( TenBarsAheadOfPatternFound, shapeUpArrow , shapeNone ), colorWhite, 0, L );
for( i = 0; i < BarCount; i++ )
if( TenBarsAheadOfPatternFound[i] ) PlotText( ""+highOfPreviousPatternFound[i] , i, H[ i ]+atr5[i], colorWhite );
If there are more than one patternFound in a range of 10 bars than issue of referencing will arise as highOfPreviousPatternFound always refer to previous patternfound without knowing that there is another patternfound in between.
Now this can easily be solved by
highOfPreviousPatternFound=ValueWhen(patternFound, H, 1);
but i don't how many patternfound are there in between. I can use a loop with the loopcounter going from 1 to 10 and solve it easily.
But is there a way to solve it without loops.