How to Build a Close Location Value Scanner in Thinkorswim Using thinkScript
Beginner Trading Tutorial | Stock Hacker | thinkScript
A candle's closing price tells only part of the story. Two stocks can finish a trading session with the same percentage gain, yet exhibit different price behavior within their respective trading ranges. One may close near its session high, while the other gives back most of its intraday gains. A Close Location Value (CLV) scanner helps distinguish these situations by measuring where the closing price sits relative to the candle's high and low.
In this tutorial we develop a complete thinkScript scanner for Thinkorswim Stock Hacker that identifies candles closing near the upper or lower portion of their trading ranges. The scanner combines a location threshold, a minimum percentage range and optional completed-bar evaluation. Its purpose is to produce a focused watchlist rather than an automatic buy or sell recommendation.
1. Understanding Close Location Value
The conventional CLV formula is CLV = ((C − L) − (H − C)) / (H − L), where H is the high, L is the low and C is the close. The numerator compares the distance from the low with the distance from the high. The denominator normalizes the result to the candle's entire range. For a valid nonzero-range bar, CLV lies between −1 and +1.

| CLV | Interpretation |
|---|---|
| +1.00 | Close at the high |
| +0.60 | Close at 80% of the range |
| 0.00 | Close at the midpoint |
| −0.60 | Close at 20% of the range |
| −1.00 | Close at the low |
CLV describes the internal structure of an individual candle. It is not the percentage change from the previous close, nor is it a measure of buying volume. A stock can gap down and close near the high of its new trading range while remaining below yesterday's close. Conversely, a stock can gain on the day but close near its intraday low.
2. Worked example: translating a price into a scan threshold
Suppose a stock records a high of $110, a low of $100 and a close of $108. All prices in this tutorial are hypothetical. The range is $10; the close is $8 above the low and $2 below the high. CLV is (8 − 2) / 10 = +0.60. The close is 80% of the way up the range. A bullish threshold of 0.60 therefore includes this bar.
Calculate the fraction of the range above the low as (CLV + 1) / 2. A threshold of 0.80 means a bullish close must occupy the upper 10% of the range. The bearish calculation is symmetric: a value of −0.60 corresponds to the lower 20%. A threshold of zero permits the midpoint in either direction.
3. Why a minimum-range filter matters
A bar with a high of $100.20, low of $100 and close of $100.20 has CLV of +1.00 despite moving only 20 cents. Without a range requirement, very narrow bars could dominate the list, especially in quiet markets or at short aggregations. We therefore calculate percentage range as 100 × (H − L) / L, using the low as the denominator, and require it to meet a configurable minimum of 0.50% by default.
This is not ATR or a volatility-adjusted signal. The purpose is to compare the size of each candle relative to its own price level. Choose the range threshold according to the aggregation and instruments you scan. The program is designed for instruments with positive prices; the denominator check explicitly excludes zero or negative lows.
4. Complete thinkScript scanner
# PatternSmart Close Location Value Scanner
# Thinkorswim Stock Hacker
# One Boolean scan output
input direction = {default Bullish, Bearish};
input clvThreshold = 0.60;
input minRangePercent = 0.50;
input useClosedBar = yes;
# Select completed or developing candle
def h = if useClosedBar then high[1] else high;
def l = if useClosedBar then low[1] else low;
def c = if useClosedBar then close[1] else close;
# Calculate candle range
def barRange = h - l;
# Protect against invalid and zero-range bars
def validBar = !IsNaN(h)
and !IsNaN(l)
and !IsNaN(c)
and barRange > 0
and l > 0
and c >= l
and c <= h;
# Calculate conventional CLV
def clv = if validBar
then ((c - l) - (h - c)) / barRange
else 0;
# Normalize range relative to candle low
def rangePercent = if validBar
then 100 * barRange / l
else 0;
# Constrain configurable thresholds
def threshold = Max(0, Min(1, clvThreshold));
def minimumRange = Max(0, minRangePercent);
# Directional conditions
def bullish = clv >= threshold;
def bearish = clv <= -threshold;
# Stock Hacker requires one scan plot
plot scan = validBar
and rangePercent >= minimumRange
and (if direction == direction.Bullish
then bullish
else bearish);
The study exposes exactly one Boolean scan plot, as required by Stock Hacker for standard thinkScript scans, and uses no secondary aggregation. The definitions preceding it handle data selection, input limits, range and directional tests. In completed-bar mode, the same historical offset is applied to high, low and close, preventing the accidental mixture of values from different candles.
5. Configurable inputs
| Input | Default | Purpose |
|---|---|---|
| direction | Bullish | Choose upper or lower closing locations |
| clvThreshold | 0.60 | Minimum directional CLV |
| minRangePercent | 0.50 | Exclude narrow bars |
| useClosedBar | yes | Evaluate the previous completed candle |
The threshold is constrained to the interval zero to one; the percentage range minimum is constrained to a nonnegative value. Start with the defaults and compare results before increasing selectivity. Higher thresholds reduce the number of matching bars, but they do not establish that the remaining signals are more profitable. For intraday scans, a 0.50% range requirement may exclude much of a low-volatility universe, so compare the output at your chosen timeframe.
6. Four tests for the default bullish configuration
| High | Low | Close | CLV | Expected result |
|---|---|---|---|---|
| 110 | 100 | 108 | +0.60 | Pass |
| 110 | 100 | 105 | 0.00 | Reject: location |
| 100.20 | 100 | 100.20 | +1.00 | Reject: range 0.20% |
| 100 | 100 | 100 | Undefined | Reject: zero range |
The first example demonstrates an inclusive threshold. The third illustrates the difference between a strong location and a meaningful absolute price movement. The last illustrates why a zero-range guard is necessary: a zero denominator makes CLV undefined, even though the program assigns a safe fallback value internally. The separate validBar condition prevents this fallback from becoming a match.
7. Installation and scan workflow
- Open Thinkorswim and select Scan, then Stock Hacker.
- Add a Study filter and select the custom study editor.
- Paste the complete code, keeping its single scan plot.
- Choose the aggregation period for the filter and configure the inputs.
- Select a stock universe, run the scan, and inspect several matching charts manually.
Daily aggregation is useful for watchlist preparation, while five-minute or fifteen-minute aggregation can be used for intraday research. Check that the charts and scan share comparable session settings and aggregation periods. If a chart includes extended-hours bars while a scan does not, the high and low being compared can differ.
8. Completed bars and practical validation
With useClosedBar enabled, the code evaluates bar [1]. While the current bar is forming, that avoids changing CLV each time the last price moves. However, it is an explicit historical offset, not an automatic determination that the latest market session has ended. At the end of a session you may see the previous bar until a new bar appears. Turning the setting off evaluates the latest bar, whose signal can change before the close.
Before relying on results, manually calculate CLV for a handful of symbols and confirm the matching range percentage. Test both bullish and bearish modes, a boundary value, a narrow candle and a zero-range bar if available. Compare different aggregations and check data availability for illiquid symbols. Finally, record how often candidates disappear in developing-bar mode. These checks distinguish an implementation error from normal updates to live market data.
9. Where the scanner fits in a trading process
Use the scan as a preliminary filter, then examine trend direction, nearby support and resistance, liquidity and volume. A close near the high can reflect continuation, a temporary rebound or the final stage of an exhausted move. A low CLV does not automatically justify a short position. The scanner contains no order logic, position sizing, stops or expected-return model.
If you are interested in customizing this free scanner with volume filters, alerts or additional confirmation rules, contact us through our Custom Trading Software Development Services.
This educational example has not been compiled or tested in a live Thinkorswim installation. Review and test the source in your own platform before use. Trading involves risk and no indicator guarantees future returns.