Thanks Ian. To calculate the highest range of the previous 20 days you would need to get the highest high and lowest low, and calculate the range as a % of the highest high.
This will calculate when that range is less than 20% (which is quite wide over a short period) and the last high broke out 2% higher than the 20 day high:
H20 = HIGHESTHIGH(BARS=20);
L20 = LOWESTLOW(BARS=20);
//Hi - Low Range;
R20 = H20 - L20;
//Range as a % of high > 20%;
(R20/H20 < 0.2) and //and High > 2% higher;
HIGH() > (H20*1.02)
I’ve used your script in the Scanning Manager with a sample workbook and it looks like it is identifying the breakout correctly.
Next step is to test it in the Backtester with some different variables. (Yes, the 20% is quite wide, but different values will be used in backtesting.)