Intermediate Trading Tutorial | thinkScript Stock Hacker
Long lower shadows are easy to recognize on a chart, but they are harder to compare consistently across stocks with different prices and volatility. A two-dollar lower shadow can be extraordinary in a quiet stock and completely ordinary in a volatile instrument. This tutorial develops a rule-based Thinkorswim scan that evaluates the shape of the most recently completed candle and also asks whether its total range is meaningful relative to its recent history. It is a screening tool, not a recommendation to enter a trade.
Separate candle geometry from activity
There are three independent measurements. The first is the lower shadow, the distance from the low to the lower of the open and close. The second is the upper shadow, measured from the higher of the open and close to the high. Both are divided by the full high-low range. These fractions are unitless, so the same rules can be applied to differently priced securities. The third measurement compares the full range of the candidate candle with the mean high-low range of the twenty earlier candles. This prevents a small, nearly inactive candle with a visually long wick from passing solely because of its proportions.
| Input | Default | Purpose |
|---|---|---|
| lookback | 20 | Number of prior bars used for the range baseline |
| minLowerFraction | 0.35 | Minimum lower shadow share |
| maxUpperFraction | 0.15 | Maximum upper shadow share |
| minRangeMultiple | 1.0 | Minimum candidate range relative to prior mean |
Worked example: two candles with equal ranges
Suppose the candidate bar has a high of 110 and a low of 100. Its open is 105 and its close is 109. The range is 10, the lower wick is 5, and the upper wick is 1. Dividing by 10 gives 50% and 10%. Both shape tests pass. If the average range of the twenty earlier bars is 8, the activity ratio is 10 / 8 = 1.25; the range condition passes too. This example would appear in the results once that candle is the previous completed bar.

Now consider an open of 108 and a close of 103, with the same high and low. The lower wick is 3 and the upper wick is 2. The fractions are 30% and 20%. Neither shape test passes, even if the total range is large enough. Notice that the logic does not require a green candle. A red candle can pass if its geometry meets the three conditions. Adding a bullish-body rule would change the hypothesis, not merely improve the existing implementation.
Complete thinkScript scan
# PatternSmart - closed-bar lower wick rejection scan
input lookback = 20;
input minLowerFraction = 0.35;
input maxUpperFraction = 0.15;
input minRangeMultiple = 1.0;
# Evaluate the last completed bar, not the forming bar
def barRange = high[1] - low[1];
def lowerWick = Min(open[1], close[1]) - low[1];
def upperWick = high[1] - Max(open[1], close[1]);
# Baseline excludes the candidate bar
def priorMean = Average(high - low, lookback)[2];
def valid = !IsNaN(high[lookback + 1]) and
!IsNaN(priorMean) and priorMean > 0 and barRange > 0;
def lowerFraction = if barRange > 0 then lowerWick / barRange else 0;
def upperFraction = if barRange > 0 then upperWick / barRange else 0;
# Stock Hacker requires exactly one Boolean plot
plot scan = valid and
lowerFraction >= minLowerFraction and
upperFraction <= maxUpperFraction and
barRange >= minRangeMultiple * priorMean;
Why the offsets matter
The unindexed high, low, open and close refer to the current bar, which may still be changing. The script evaluates the previous bar using index one. The baseline is the twenty-bar average shifted by two bars, meaning that it covers bars two through twenty-one. It therefore excludes the candidate as well as the forming bar. Without that exclusion, an unusually large candidate could raise its own baseline and change the meaning of the test. The scan has exactly one Boolean plot, with the other calculations defined as intermediate variables.
On a five-minute aggregation, for example, a candle that ends at 10:05 becomes the previous bar when the next bar begins. The scan then evaluates that completed observation. Actual scan refresh timing and available data depend on the platform; a result is not guaranteed to appear at the exact boundary. At the end of a session, the latest finished session bar may remain the current bar until a new one exists, so this deliberately conservative convention can delay its evaluation.
Install in Stock Hacker
- Open Scan and select Stock Hacker in Thinkorswim.
- Select a suitable scan universe. Add a Study filter and open its custom thinkScript editor.
- Replace the editor contents with the complete script. Choose the desired aggregation in the study filter and save it.
- Run the scan and inspect the corresponding previous candle on a chart with the same aggregation and session settings.
- Check several candidates manually before changing thresholds or using results in a watchlist workflow.
The source is designed for the native thinkScript scan editor; it has not been compiled in a live Thinkorswim installation here. Platform restrictions and data availability should be checked in your own environment.
Parameter tuning without overfitting
Raising the minimum lower fraction from 0.35 to 0.50 asks for more pronounced rejection geometry and reduces the number of eligible observations. Reducing the upper limit from 0.15 to 0.10 imposes a stronger asymmetry. These parameters affect geometry rather than absolute volatility. Raising the range multiplier instead filters activity. A value of 1.5 requires a candidate range at least fifty percent larger than the recent mean. Combining all three strict settings can produce very few results, so vary one at a time and record counts before evaluating subsequent returns.
A shorter baseline adapts rapidly to changes in trading activity but can be unstable after a handful of abnormal bars. A longer one is smoother but can compare a current volatile session with a quieter regime. Start with twenty, and examine the distribution of range ratios for the chosen aggregation. Fractions should be between zero and one, the range multiplier nonnegative, and lookback a positive integer.
Validation and common failure cases
Test a zero-range candle: it must fail without division by zero. Test exact equality at 35%, 15%, and a range ratio of one; the comparisons are inclusive, subject to floating-point representation. Check that sufficient history exists and that a flat baseline does not produce false signals. Compare an active current candle against the previous candle while prices move; the candidate values should remain unchanged until another bar becomes available. Match extended-hours settings and aggregation when comparing a chart with scan results. Illiquid symbols can have stale prints or unrepresentative wicks, and corporate actions can distort data. The high-low baseline intentionally does not measure overnight gaps; this is not an ATR calculation.
What the scanner cannot establish
The candle geometry records the observed price path only through OHLC summary values; it does not reveal intrabar sequence, order flow, or the identity of participants. A lower wick may reflect temporary liquidity gaps rather than durable buying support. The rule does not establish a trend reversal, quantify execution costs, or provide position sizing and exits. To test a trading hypothesis, define future evaluation horizons independently, include fees and slippage, and use out-of-sample data. Never evaluate a signal using information from the future candle.
If you would like a mirrored upper-wick version, a chart indicator, or additional volume and trend filters, contact us for Custom Thinkorswim indicator Development Services.
Risk disclosure: This example is educational, not investment advice. Trading can result in substantial losses; hypothetical examples do not demonstrate profitability.