Advanced Trading Tutorial — Thinkorswim
A large candle does not necessarily imply persistent directional movement. This Stock Hacker custom indicator compares absolute close-to-close displacement with the sum of completed candle ranges. Unlike a conventional close-to-close efficiency ratio, the denominator measures intrabar excursions. It is a useful research filter for distinguishing directional progress from repeated intrabar activity, not a prediction of the next return.
Define the measurement
For a positive integer lookback N, sum the high minus low of each of the previous N completed candles. Measure the absolute difference between the most recent completed close and the close immediately preceding that window. Divide the latter by the former only when the denominator is positive and sufficient history exists. A threshold of 0.45 is an illustrative starting point, not an optimized value. The numerator is unsigned, so both rising and falling markets can qualify. Because overnight gaps are not included in the denominator, the ratio can exceed one; do not interpret it as a bounded probability.

Figure: five hypothetical completed ranges of 2, 3, 2, 3 and 2 sum to 12. If the preceding close is 100 and the final completed close is 106, displacement is 6 and the ratio is 0.50, passing 0.45. A final close of 102 instead produces 2/12 = 0.167, which fails. These are arithmetic examples, not historical results.
Native thinkScript implementation
# PatternSmart: closed-bar range efficiency scan
input length = 5;
input threshold = 0.45;
# All observations end at the previous completed bar.
def totalRange = Sum(high[1] - low[1], length);
def displacement = AbsValue(close[1] - close[length + 1]);
def ready = !IsNaN(close[length + 1]) and totalRange > 0;
def ratio = if ready then displacement / totalRange else 0;
# Stock Hacker requires a single Boolean plot.
plot scan = ready and ratio >= threshold;
Use length as a positive integer and threshold as a nonnegative number. Sum operates over the specified lookback; the one-bar offset applies to every range in that window. The close at length plus one is the anchor before the first measured candle. The ready condition rejects missing anchor data and zero denominators. The conditional expression prevents division by zero. The final scan is the only plot, and it evaluates to a Boolean. This is a scan filter rather than an order-generating strategy.
Installation and timing
In Thinkorswim open Scan, select Stock Hacker, add a Study filter, choose Custom and open the thinkScript editor. Replace the existing expression with the complete script, choose the intended aggregation and scan universe, then run the scan. Interface labels can vary by version. For a chart-based diagnostic, create a separate study and replace the final plot with a numeric ratio plot; do not add that plot to the scanner. Keep the scanner at exactly one Boolean plot.
On a five-minute aggregation the current five-minute candle is excluded. A candle ending at 10:05 becomes eligible once the next candle exists. The result therefore does not respond to intrabar high, low or close changes of the forming candle. It is not a promise that historical data never change: corrections, session settings, corporate actions and aggregation changes can alter results. On illiquid symbols a new bar may not appear immediately, and a scan refresh can lag the chart. The filter identifies a condition, not a one-time crossing event, so a symbol can remain in the results for several bars.
Testing and interpretation
Start with the five-range example and calculate the numerator and denominator by hand. Compare a separate diagnostic chart study with the scanner using the same symbol, aggregation and extended-hours settings. Check a flat window, a window with a large overnight gap, an insufficient-history symbol and a sequence of alternating candles. For a flat window the filter should reject a zero denominator. A gap can produce a ratio above one even when the arithmetic is correct. If this behavior is undesirable, a future variant could use true range, but that is a different definition and should be tested independently.
Try several thresholds on a fixed historical sample, then evaluate them on a separate sample. Compare the number of qualifying symbols rather than assuming a higher ratio produces better returns. Keep a record of aggregation, session template and data source. Avoid selecting a threshold solely because it fits a handful of favorable charts. This indicator does not model liquidity, spread, commissions or execution. It also ignores the direction of the move, so a separate directional condition may be useful in a different research workflow. Do not confuse high displacement efficiency with low risk: a sharp news-driven move may score highly while being difficult to trade.
For a customized chart companion, session-aware calculation or additional scan conditions, see Custom Thinkorswim indicator Development Services.
Risk disclosure: educational example only; trading involves risk of loss. The code has not been compiled or tested in Thinkorswim in this run. Validate it in your own environment before relying on it.