Beginner Trading Tutorial — Confirmed Relative Volume in Thinkorswim
Raw trading volume is difficult to compare across symbols. A thousand shares may be unusually active for one security and insignificant for another. A relative volume indicator compares an observation with a reference drawn from the same instrument. This tutorial builds a simple completed-bar relative volume study and a matching Stock Hacker filter in thinkScript. The goal is to identify unusually active completed candles without confusing a partially formed candle with a finished one.
Define a fair reference window
Use the previous completed candle as the candidate. Calculate the arithmetic mean of the N candles immediately before it. Divide the candidate volume by that mean. A ratio of one indicates that the candidate equals its reference average, while a ratio of 1.5 indicates that it is 50 percent above that average. The candidate is excluded from the reference so that a large observation does not inflate its own benchmark. The current forming candle is excluded as well. When the reference mean is zero, no meaningful ratio exists.

Worked example
With length set to three, suppose the preceding volumes are 800, 1000 and 1200. Their mean is 1000. The candidate volume of 1600 produces a ratio of 1.60 and passes a threshold of 1.5. In a separate example with the same baseline, a candidate of 1500 passes exactly at the threshold; a candidate of 1400 produces 1.40 and fails. If all three reference observations are zero, the study leaves the ratio undefined and the scan returns false. These are hypothetical numbers rather than historical market results.
Consider why exclusion matters. If the 1600 observation were included in a three-bar reference with 1000 and 1200, the mean would become approximately 1266.67. The resulting ratio would be approximately 1.263, below the threshold. That is not a mathematical error, but it measures a different relationship. For this tutorial the comparison is intentionally against information available before the candidate began.
Complete chart study
declare lower;
input length = 20;
input threshold = 1.5;
# Candidate is the previous completed bar.
def baseline = Average(volume[2], length);
def valid = !IsNaN(volume[1]) and baseline > 0;
plot Ratio = if valid then volume[1] / baseline else Double.NaN;
plot Level = threshold;
Ratio.SetDefaultColor(Color.CYAN);
Level.SetDefaultColor(Color.GRAY);
Ratio.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Complete Stock Hacker filter
input length = 20;
input threshold = 1.5;
# Exactly one Boolean output for Stock Hacker.
def baseline = Average(volume[2], length);
plot scan = if baseline > 0 and !IsNaN(volume[1])
then volume[1] >= threshold * baseline
else no;
The chart study has two plots: a histogram and a horizontal threshold. The scan is a separate script with exactly one Boolean plot. Do not paste the two-plot chart study directly into Stock Hacker. Both scripts use the same reference and threshold; the scan compares volume with threshold times the baseline, avoiding division in its Boolean expression.
Understanding the offsets
In thinkScript, volume[1] refers to the preceding bar, while volume[2] refers to the bar before that. Average(volume[2], length) averages the shifted series over the specified number of observations. For length three, the reference comprises offsets two, three and four. The candidate is offset one. Offset zero, which may still be changing, does not participate. The chart ratio is plotted at the current bar position, so the observation is intentionally shifted one bar later than the candle whose volume it describes. This is important when comparing the histogram with the chart's ordinary volume bars.
The valid condition prevents division by a nonpositive reference and suppresses missing candidate data. The threshold should be positive and length should be a positive integer. The default length of twenty is a starting point for experimentation rather than an optimized setting. A shorter length responds more quickly to recent activity but can produce unstable reference values. A longer length is smoother but can remain influenced by older market conditions.
Installation and scan setup
In the Thinkorswim desktop platform, open Charts, then Studies and Edit Studies. Create a new study, paste the chart source, give it a unique name and add it to the chart. The lower panel shows the ratio and reference threshold. To create the scanner, open Scan and Stock Hacker, add a custom study filter, open the thinkScript editor and paste only the scan source. Select the intended aggregation period and scan universe. Use matching aggregation and extended-hours settings when comparing chart and scanner results. The source has not been compiled or run in the platform here; validate both scripts in your installation before relying on them.
Closed-bar timing and repainting
The previous candle is used because the current candle's volume grows during its lifetime. On an intraday chart, a completed observation becomes eligible when the next bar is recognized. On a daily chart, the previous daily candle remains the candidate throughout the current session. The scripts do not intentionally repaint confirmed observations because their inputs are completed historical bars. Feed corrections, session changes and historical data adjustments can still alter results. A scanner is not a tick-by-tick event log: its refresh frequency and data availability may affect when a qualifying symbol appears. A symbol can remain in the results until the candidate changes.
Testing and practical limitations
Start with length three and compare the histogram against the preceding four completed volume bars. Check exact equality at the threshold, zero baseline, missing history and a candidate below the threshold. Observe a forming candle and verify that its growing volume does not change the confirmed ratio. Compare scan results with the chart at the same aggregation. If the results differ, check session settings, symbol data and refresh timing before changing the formula.
Volume is often strongly seasonal within a trading day. Opening and closing activity may naturally exceed midday activity, so a simple rolling mean is not a time-of-day-adjusted benchmark. Volume also differs across asset classes and data feeds; some instruments may not provide comparable traded volume. A high ratio does not indicate whether buyers or sellers are dominant, nor whether a price move will continue. It may reflect news, index rebalancing or a temporary liquidity event. A more advanced study could compare matching time slots across previous sessions, or require a minimum absolute volume to avoid ratios based on tiny denominators. Test such extensions on independent data and account for realistic transaction costs.
For custom session baselines, alerts or combined price and volume filters, contact our Custom Thinkorswim indicator Development Services.
Risk disclosure: educational material only. Trading involves risk of loss. Hypothetical examples do not demonstrate profitability.