Require contraction before a breakout
Breakouts after quiet trading and breakouts after already-expanding ranges may behave differently. This Sierra Chart ACSIL example measures recent bar-range compression before considering a long entry. It uses high minus low, not true range, so it does not measure overnight gaps directly.
Define the rule
For a completed signal bar, calculate mean high-low range over the five preceding bars and over the 20 preceding bars. The short window is included in the longer window. Require the ratio to be at most 0.60 and require the signal close to exceed the highest high of those preceding 20 bars. A long-window mean of 4 points and a short mean of 2 points gives 0.50; 3.6 points gives 0.90. Only the first passes compression, and neither is an entry without the breakout.

Hypothetical compression measurements. The green result still requires a separate price breakout.
ACSIL implementation
// Inside an AutoLoop ACSIL study, after defaults.
if (sc.Index < 20 ||
sc.GetBarHasClosedStatus() != BHCS_BAR_HAS_CLOSED)
return;
double sum5 = 0, sum20 = 0;
float resistance = sc.High[sc.Index - 1];
for (int k = 1; k <= 20; ++k)
{
int i = sc.Index - k;
double range = sc.High[i] - sc.Low[i];
sum20 += range;
if (k <= 5) sum5 += range;
if (sc.High[i] > resistance)
resistance = sc.High[i];
}
double mean20 = sum20 / 20.0;
bool longSignal = mean20 > 0 &&
(sum5 / 5.0) / mean20 <= 0.60 &&
sc.Close[sc.Index] > resistance;
// Use longSignal in the guarded entry routine.
Use sc.AutoLoop = 1 in defaults. Excluding the signal bar prevents expansion from changing its own compression filter. The last bar may remain unconfirmed until a new bar arrives; see the ACSIL function reference. The fragment calculates a signal only. A complete trading study must check position, working orders, allowed trading hours and duplicate submissions before sc.BuyEntry; configure protective attached orders and a maximum position size.
Exit and validation design
Test a protective stop below the signal low and a close below the preceding ten-bar low as a separate market exit. Normalize protective prices to valid ticks, and reject invalid risk distances. Compare 0.4, 0.6 and 0.8 ratios with an unfiltered baseline using identical exits, data and costs. Include gaps, replay, quiet periods and live simulation; record missed breakouts, trade frequency and drawdown. A low range can reflect illiquidity rather than genuine consolidation. The fragment has not been compiled or backtested here. Trading involves risk and stops may fill worse than requested.
For custom execution and strategy rules, see Custom Sierra Chart strategy Development Services.