Intermediate Trading Tutorial | Thinkorswim

Range expansion is not necessarily a breakout. This scanner identifies a narrow completed candle followed by a wide completed candle, relative to a common historical baseline. It deliberately ignores direction and does not use the live candle. The purpose is to build a reproducible watchlist rather than an automatic entry system.

Define the event

Measure each candle using high minus low. Let the baseline be the mean of five completed ranges preceding the setup candle. A setup qualifies when its range is no greater than 65% of that baseline. The next candle qualifies when its range reaches at least 150% of the same baseline. Keeping the denominator fixed avoids letting the expansion candle inflate its own threshold. Use positive input lengths and positive ratios, preferably a compression ratio below one and an expansion ratio above one.

For example, if the baseline is 8 points, a setup of 4 points passes the 5.2-point ceiling and an expansion of 12 points meets the 12-point floor. Equality is accepted. A 10-point expansion fails. A zero baseline is rejected rather than interpreted as a valid setup.

Closed-Bar Range Compression and Expansion Scanner

Figure: illustrative ranges of 8, 7, 6, 5, 4 and 12 points; blue denotes preceding candles, green the expansion, and the red reference line represents 5 points. The illustration is schematic, not the full five-bar baseline example.

Complete thinkScript source

# Closed-bar range expansion scanner
input length = 5;
input compressionRatio = 0.65;
input expansionRatio = 1.5;
def r = high - low;
# Baseline excludes both candidate and setup bars.
def baseline = Average(r[3], length);
def ready = !IsNaN(baseline) and baseline > 0;
def compressed = r[2] <= baseline * compressionRatio;
def expanded = r[1] >= baseline * expansionRatio;
plot scan = ready and compressed and expanded;

Indexing and timing

Index zero is the developing candle. Index one is the expansion candidate and index two is the compression candidate. The baseline begins at index three and extends back for the chosen length. The scan can become true on the first update of the next bar, not at the exact closing tick of the expansion candle. It remains stable during that new bar assuming historical OHLC data is unchanged. No future references are used. Historical data corrections, session changes and aggregation changes can alter results; this is not a guarantee against every kind of recalculation.

Installation

Open Scan, select Stock Hacker, add a Study filter and choose Custom. Open the thinkScript editor, replace the default expression with the source, choose an aggregation period and save the filter. The script has exactly one Boolean plot. For visual debugging, the same script may be added as a custom study, although its Boolean output is not a price overlay. Use a separate lower study if you want to display the underlying ranges.

Testing and interpretation

Start with liquid instruments and a consistent session definition. Compare the scan against a manually calculated table of completed candles. Test equality at both thresholds, insufficient history, flat bars, and a large live candle that must not affect the result until the next bar begins. Compare extended-hours settings before comparing results across charts. A gap can move price substantially without producing a wide high-low range; true range would be a different design. A wide candle can close near its midpoint and provide no directional evidence. A scan result is therefore a prompt for further analysis, not a buy or sell instruction.

For a customized directional filter, alert or chart study, explore Custom Thinkorswim indicator Development Services.

Limitations and risk

The source is provided for educational purposes and has not been compiled or tested in the platform in this run. Historical patterns do not establish profitability. Trading involves risk of loss, including slippage and gaps. Validate independently before use.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.