HIGHESTHIGH function reference a variable for look back period


I’m trying to find the highest high since a new 13 week low was created. The date of the 13 week low will only change when the low of the current bar is less then the previous 12 weeks. I want to use the date of the 13 week low bar as a variable and use the HIGHESTHIGH function to find the highest high since the date of the 13 week low.

Is it possible to reference a variable in the HIGHESTHIGH function? Below is what I have done so far but script is not valid for H1.

//Lowest low for the last 13 weeks


//Low of current bar is not lower then the previous 12 weeks

L2 = LOW() < L1;

//Date since there was a new 13 week low


//Number of weeks since new 13 week low

B2 = (BARDATE() - B1)/7;

//Highest high since new 13 week low

H1 = HIGHESTHIGH(RANGE=Look Back Period, BARS = B2);



The following script could work, but it’s only valid for current data (ie you can’t scan for historical instances).

V1 = LOW() CrossesBelow LOWESTLOW(BACKTYPE=Weeks, BARS=13);

In this example, V1 looks for the new 13 Week Low being set. $a looks for the number of bars since the new low was set, and the Highest High function references this count and sets the back bars accordingly.

In the image below you can see on ASX the last 13 week low was 144 bars ago. The Highest High (blue) line is using a lookback period of 144 bars.


If you enabled training mode and started hiding bars, the Highest High line would adjust based on the $a variable count.

Hi Matthew,

Thank you for your reply. That works fine. I see what you mean, it’s only valid for current data. Is it possible to view historical instances from current data instead of using training mode?

Using the show plot like you have done above, when there is a new a new 13 week low the HighestHigh would reset to the high of the bar that created a new 13 week low. It would gradually step up when there are new highs until a there is new 13 week low where it would reset again.

Thank again


The following alternative script should work on a historical basis as well (no need for Training Mode)…

Signal = LOW() CrossesBelow LOWESTLOW(BACKTYPE=Weeks, BARS=13);
IF(HHSinceLL <= 0, If(High() > Previous(), High(), Previous()), HHSinceLL)

Hi Matthew.

Thanks for that. That seems to works fine.

Kind regards