Problem of referencing

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 ); 
		
		

TestReferencing

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.

Let me give a simpler example.

Imagine the scenario. Lets say the pattern you are working with has 5 legs namely A,B,C,D,E. You are at the bar where first 4 legs characteristics of the pattern are stored. For example barLength, PriceLength of first 4 legs etc are available here. now from this bar (lets call it patternFoundBar) you have to calculate the 5th leg leg-E which is related to Leg-A. so you refer Leg-D and from there twice the length of leg-A takes you to the high of Leg-E.

LegE_High=Ref(Ref(H, barlength_Of_LegA * 2), barRef_LegD);

but the problem here is barlength_Of_LegA is stored at patternFoundBar but when you do Ref( ,barRef_LegD) everything within the Ref() refers to LegD bar.
My question is:
Is it possible to use the calling bars array values at the refered bar? something like below

LegE_High=Ref(Ref(H, barlength_Of_LegA_storedinCallingBar* 2), barRef_LegD);

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.