Advanced Trading Tutorial | thinkScript | Range-weighted price structure
Closing near the high of a candle is often interpreted as evidence of upward pressure. Yet a narrow candle and a wide candle need not deserve equal influence in a rolling statistic. This Thinkorswim study measures the aggregate distance of completed closes from their respective lows, divided by the aggregate high-low range. It offers a compact way to inspect where price has tended to finish within recent ranges, without assigning equal weight to every candle.
Calculation and interpretation
For each completed bar define R = High − Low and O = Close − Low. The indicator is 100 × Sum(O,N) / Sum(R,N). For ordinary OHLC data the result lies between zero and 100. It is equivalent to weighting each individual close-location percentage by its range. A wide bar therefore contributes more to the aggregate than a narrow bar. A zero-range bar contributes zero to both sums; an entirely flat window produces no value. The neutral reference is 50. Values above 50 indicate that the aggregate offsets exceed half the aggregate range, not that a majority of bars necessarily closed above their midpoints.
Worked example
Assume three completed bars have ranges of 10, 4 and 6 points, and close-minus-low offsets of 8, 1 and 3 points respectively. Their individual close locations are 80%, 25% and 50%. An equal-weight average would be approximately 51.67%. The range-weighted calculation instead yields 100 × (8 + 1 + 3)/(10 + 4 + 6) = 60%.

This difference is intentional: the first bar accounts for half the combined range and therefore half the weight. Neither statistic is inherently superior. The weighted version is useful when the analyst wants larger price excursions to have greater influence, while the equal-weight alternative describes a typical candle regardless of its size.
Complete thinkScript study
declare lower;
input length = 20;
# Use completed bars only.
def span = high[1] - low[1];
def offset = close[1] - low[1];
def totalRange = Sum(span, length);
def totalOffset = Sum(offset, length);
plot Location = if totalRange > 0 then
100 * totalOffset / totalRange
else Double.NaN;
Location.SetDefaultColor(Color.CYAN);
plot Neutral = 50;
Neutral.SetDefaultColor(Color.GRAY);
Installation and parameters
In Thinkorswim open Charts, select Studies, then Edit Studies and create a new study. Paste the source, give the study a descriptive name, save and add it to the chart. The lower pane displays the location series and its neutral reference. Use a positive integer length; the default is 20 completed bars. A shorter length such as five is more responsive to a single wide candle, while a longer length such as 50 distributes influence across more observations. Compare several lengths on the same symbol and aggregation rather than choosing a setting solely because it fits a past move. This is a chart study, not a Stock Hacker scan. The source has not been compiled in a live Thinkorswim installation for this tutorial.
Why completed bars matter
Every OHLC reference uses offset one. On the currently forming candle the sums therefore begin with the immediately preceding completed candle. The result becomes available at the next bar and does not incorporate the forming candle's changing high, low or close. There is no forward reference. Historical data corrections or changes to session settings can still change the underlying series. Allow sufficient history for the rolling calculation before interpreting the first plotted values.
Practical analysis
In a rising market, a persistently high reading may describe closes concentrated toward the upper portions of recent ranges. A falling reading while price rises may indicate a change in closing behavior, but it does not establish a reversal. A single large news candle can dominate the calculation for several bars and cause an abrupt change when it leaves the rolling window. This is a consequence of range weighting rather than a software defect. The indicator does not use volume, distinguish buying from selling orders, or measure actual capital flows. Consider plotting an equal-weight close-location statistic alongside it when investigating the influence of unusual ranges.
Testing checklist
- Set length to three and compare with manually calculated OHLC values.
- Verify that closes at the high and low produce 100 and zero respectively when all usable observations share that property.
- Check an entirely flat window for an undefined result.
- Observe the current bar during live updates; its own OHLC changes should not enter the calculation.
- Compare regular and extended-hours charts, and inspect the effect of a large bar leaving the sample.
Limitations
High-low range excludes gaps between candles. A large overnight price jump followed by a narrow candle may receive little weight even though the total price displacement is substantial. Synthetic chart data can also change the interpretation of the input. The indicator is not a volatility-adjusted return, probability estimate or standalone trading signal. For further customization, including session filters or integration with existing studies, contact our Custom Thinkorswim indicator Development Services.
Risk disclosure: The example is hypothetical and intended for education. No profitability or future performance is implied. Validate any trading application independently and account for costs and execution risk.