Signal Test for returns between first and last signal

Hii Sir,

Rather than using fixed day period i want to calculate the returns between first and last signal.

Which means lets say first 52 week low, i am able to find first signal using below script. But i am stuck how to find the last signal after v4. If i am able to calculate the same using a script i will be able to use it in signal tester or back tester to find out returns.

Also in order to clearly explain i have attached screen shot using chart. In the attached chart i want to find the script for red circled bar after the show bar in each case and then find the returns rather than a constant time period.

v1 =LOW()<DONCH(BARS=252, INCURBAR=True, DEFAULT=LowerLine)[1]; 
v2 = HIGH() > DONCH(BARS=252, INCURBAR=True, DEFAULT=UpperLine)[1]; 
v3 = SWITCH(v1,v2); 
v4 = v3 ChangeTo 1; 
v4

Hi,

Looking at your script and screenshot, can you confirm that you want to measure the difference in price from the first instance the Low crosses below the Donchain lower band, to the last instance the Low crosses below, then reset the measure after the High crosses above the upper band?

Using the code in your screenshot, the first trigger is on Sep 11 2008, there are 5 more lows crossing the lower band before the high crosses above the upper band on October 29 2010.

The last instance before that cross is Sep 6 2010, which is different to the area you marked on the chart.

Ex4

If you were wanting to measure the area you marked on the chart you would need to specify a rule that works for that scenario, something that could be scripted as a triggering criteria.