Intermediate Trading Tutorial — Confirmed Close Location and Range Expansion Scan

A candle closing near its high is not necessarily exceptional. A narrow candle can close near its high just as easily as a wide candle. This Thinkorswim Stock Hacker tutorial combines two independent measurements: the location of the close within a completed candle and the size of that candle relative to earlier ranges. The purpose is to identify a reproducible geometric condition rather than predict the next price movement.

Define the two filters

Close location is the difference between the closing price and the low divided by the high minus the low. It is a fraction between zero and one for ordinary OHLC data. A close at the low produces zero, a close at the midpoint produces 0.5, and a close at the high produces one. A zero range is undefined and must be excluded. The second filter compares the completed range with the arithmetic mean of the preceding ten ranges. The evaluated candle is excluded from that mean so that it cannot inflate its own reference.

Confirmed Close Location and Range Expansion Scan
Three hypothetical candles share a low of 100 and a high of 110. Closing prices of 102, 105 and 108 produce locations of 20%, 50% and 80%. Only the third satisfies a 75% minimum.

Practical numerical example

Assume the preceding ten ranges are 6, 7, 8, 9, 10, 6, 7, 8, 9 and 10. Their sum is 80 and their mean is 8. With minExpansion set to 1.25, the minimum evaluated range is 10. A completed candle with low 100, high 110 and close 108 has a range of 10 and location 0.8. It passes both conditions. If its close were 105 instead, it would fail the location condition. A candle with low 100, high 106 and close 105 would pass the location condition but fail the expansion condition. Equality is accepted at both thresholds.

Complete thinkScript scan

# Confirmed close location with range expansion
input length = 10;
input minLocation = 0.75;
input minExpansion = 1.25;

# Only completed candles enter the calculation.
def span = high[1] - low[1];
def reference = Average(high[2] - low[2], length);
def location = if span > 0
               then (close[1] - low[1]) / span
               else Double.NaN;

# Reject unavailable or invalid reference values.
def valid = !IsNaN(reference) and reference > 0
            and !IsNaN(location);

# Stock Hacker requires exactly one Boolean plot.
plot scan = valid and location >= minLocation
            and span >= minExpansion * reference;

Understand the historical offsets

ThinkScript uses square brackets to refer to earlier bars. Index one is the preceding bar, and index two is the bar before that. The Average function receives a series already shifted by two bars, so a ten-period reference includes offsets two through eleven. The candidate uses offset one. This separation is deliberate: including the candidate in the reference would reduce the measured relative expansion when a large candle appears. The code defines intermediate values using def rather than plot. The only plot is scan, a Boolean expression suitable for a custom Stock Hacker study filter.

Use a positive integer length, a location threshold between zero and one, and a positive expansion multiplier. The defaults are examples rather than optimized settings. A higher location threshold selects closes nearer the high, while a larger expansion multiplier requires a larger range relative to the reference. These controls affect different dimensions and should not be interpreted as interchangeable.

Installation

Open the Scan tab in Thinkorswim and choose Stock Hacker. Add a study filter, select the custom study option and open the thinkScript editor. Replace the existing expression with the complete source. Choose the desired aggregation period in the filter settings and apply the filter. Select a suitable symbol universe. The code uses only the primary aggregation and does not require secondary aggregation or additional plots. Review any editor diagnostics. This source has not been compiled or executed in Thinkorswim here.

Closed-bar behavior and repainting

The forming candle is deliberately excluded. As the current candle changes, the candidate and its reference window remain fixed until a new bar is recognized. At that point the previous candle becomes the candidate. This means the result is available after the evaluated candle, not at an earlier intrabar price. A scan is a snapshot of the platform's evaluation and is not a guarantee of immediate notification at a bar boundary. Data corrections, session settings and aggregation changes can change historical inputs. The formula does not intentionally use future data or repaint finalized observations.

Testing the filter

First calculate the examples manually. Then inspect a chart using the same aggregation and session settings as the scan. Compare the preceding completed candle with the ten candles before it. Check a candidate exactly at both thresholds, a zero-range candidate, a zero reference, insufficient history, and a candle whose range passes but close location fails. Verify that a large forming candle does not change the result before the next bar appears. A scan may have different historical data availability from a chart, so compare the actual inputs rather than assuming identical warm-up behavior.

Interpretation and limitations

The scan describes a close near the high of a relatively wide candle. It does not establish buying pressure from order flow, volume, or the sequence of intrabar trades. It ignores gaps from the previous close and may select illiquid symbols with small reference ranges. A large range can reflect news or a reversal rather than trend continuation. Compare candidate results across market regimes, avoid optimizing thresholds on a single sample, and account for spreads and execution costs in any downstream strategy research.

For custom scan variants, volume filters or chart-study integration, contact our Custom Thinkorswim indicator Development Services.

Risk disclosure: educational content only. Trading involves risk of loss; hypothetical examples do not establish profitability.

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.