Breakout Scan Script

Hi,

I’m looking to backtest and scan for breakouts from a sideways range, something like this.

Breakout2

In its simplest form, a pattern where:

The previous (say) 20 bars were in a fairly narrow range (say) 20% between the highest high and lowest low, and

The last bar high exceeds any of the prior 20 days, and

The last bar range is substantially higher than any range of the prior 20 days.

For the last bar high, I have:

// High > the Highest High of the last 20 days.
HIGH()>HIGHESTHIGH(BARS=20)
However, I'm having trouble figuring out how to define the consolidation range.
Any suggestions?
Thanks.



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)

Thank you Darren!

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

Thanks again.