TradingView indicator calculations

Volatility Quality indicator: identify the formula before the signal

The Volatility Quality indicator combines candle direction and close-to-close movement with range measurements. VQ and VQI names cover several implementations: a cumulative line, its per-bar change, and smoothed or filtered variants. This guide uses the calculation published by LazyBear on TradingView as its reference, then adds a separately defined threshold for research. The cumulative value is in price units and has no fixed 0-to-100 scale; it is different from the Relative Volatility Index.

See the decision guide

VQ and VQI do not identify one interchangeable script

Start with the published author and version. LazyBear describes a cumulative VQI with 9-bar and 200-bar simple averages. NicoadW describes a WMA-based slope histogram with a change filter, while Loxx offers smoothing choices and pip filtering. Their displays answer different questions. A green histogram need not match a cumulative line above its slow average.

  • The public LazyBear source calls sma() even though its input labels mention EMA. Follow the executed calculation when reproducing values.
  • A script title or screenshot cannot establish parity with a protected implementation. Public source access also does not remove the author attribution and republication rules.
Published exampleOutput or processingComparison to make
LazyBear VQICumulative contribution plus 9- and 200-bar SMAsCompare the contribution, cumulative baseline and SMA lengths.
NicoadW histogramWMA price inputs, VQI slope and a filterMatch price smoothing and the series to which the filter applies.
Loxx pip-filtered VQISelectable smoothing and pip filteringCheck the pip conversion, filter rule and signal definition in that version.
Relative Volatility IndexStandard-deviation-based oscillator on a 0-to-100 scaleTreat it as a separate indicator, not a renamed VQI.

Fix the reference formula and its zero-range behavior

For ordinary OHLC bars, let P be the previous close, R = H - L and T = max(H - L, abs(H - P), abs(L - P)). When R and T are positive, calculate q = 0.5 × ((C - P) / T + (C - O) / R). The contribution is d = abs(q) × ((C - P) + (C - O)) / 2, and the cumulative line is S = previous S + d. These are the arithmetic steps in the selected public implementation.

  • The reference retains the previous q when either denominator is zero. It then calculates d using the current price changes. Carrying q is different from carrying d or forcing d to zero.
  • For this page, the first available close supplies P for the next bar; initialize q and S to zero. Missing inputs do not create a contribution. The Pine example leaves their plots unavailable and retains the accumulated state.
  • No OHLC smoothing or pip filter is present in this reference calculation. The 9- and 200-bar SMAs smooth S afterward; they do not smooth the input prices.
  • With valid OHLC and nonzero ranges, q lies between -1 and 1. Taking abs(q) removes its sign before weighting the average of the two price changes. S is unbounded and its level depends on the starting history.

Recalculate a trend, a gap and a narrow bar

This is a consecutive synthetic sequence, not a market backtest. Begin with previous close 100 and S = 0. Each row uses the preceding row's close. Prices and VQI contributions use the same arbitrary price unit; displayed results are rounded to six decimals.

  • On bar 3, C - P = 4 while C - O = -2. Thus q = (4 / 7 - 2 / 4) / 2 = 1 / 28, and d = (1 / 28) × (4 - 2) / 2 = 1 / 28. Candle color alone would classify this differently.
  • Bar 4 has a positive q but contributes only 0.025. A narrow bar can have a substantial directional ratio while adding little to the cumulative line.
  • Bar 5 makes S fall even though S remains positive. Positive S is not the same condition as positive slope.
  • Bar 7 exposes the carry rule: R is zero, so the old q survives. Its absolute value times half the gap gives 1.05. A zero-range policy that emits zero would disagree. Inspect illiquid or limit bars before interpreting this as fresh directional information.
BarO / H / L / CT / RqContribution dCumulative S
1: upward move100 / 103 / 99 / 1024 / 40.5000001.0000001.000000
2: continuation102 / 105 / 101 / 1044 / 40.5000001.0000002.000000
3: upward gap, red candle110 / 111 / 107 / 1087 / 40.0357140.0357142.035714
4: narrow advance108 / 108.2 / 107.8 / 108.10.4 / 0.40.2500000.0250002.060714
5: decline108.1 / 109 / 105 / 1064 / 4-0.525000-1.1025000.958214
6: unchanged flat bar106 / 106 / 106 / 1060 / 0-0.525000 carried0.0000000.958214
7: gap to a flat bar110 / 110 / 110 / 1104 / 0-0.525000 carried1.0500002.008214

Specify what a filter rejects and what it preserves

The optional research rule below labels a completed bar upward when d > f, downward when d < -f, and neutral otherwise. Set f in price units, with f ≥ 0; equality is neutral. This filter changes only the state and alerts. It does not modify the raw cumulative line, and it is not a reproduction of the NicoadW or Loxx filters.

  • A filter that holds the last non-neutral direction would remain upward on bars 3 and 4. A filter that drops small contributions would change S itself. Both differ from this neutral-state rule.
  • An absolute threshold does not transfer unchanged across instruments or price scales. If a script accepts pips or ticks, record the explicit conversion to price units; do not assume a pip equals the minimum tick.
  • Increasing f suppresses small changes and can delay or miss a reversal. Smoothing the input prices changes the formula before the threshold is applied. Test these choices separately on later data.
SampleUnfiltered slopeState with f = 0.05Consequence
Bars 1 and 2: d = 1UpwardUpwardConsecutive upward states are not separate start events.
Bar 3: d = 0.035714UpwardNeutralThe gap contribution is below the selected threshold.
Bar 4: d = 0.025UpwardNeutralThe narrow advance still adds to raw S.
Bar 5: d = -1.1025DownwardDownwardA negative contribution survives the filter.
Boundary d = 0.05UpwardNeutralStrict greater-than differs from greater-than-or-equal.

Audit the contribution and confirmed state in Pine Script

This Pine v6 example implements the stated arithmetic and baseline, with the separate price-unit threshold. It exposes q, d and state in the Data Window and plots the cumulative line. It omits the reference script's two SMAs so the calculation can be inspected directly. The code only displays completed chart bars and alerts when a confirmed upward state starts.

  • Use ordinary candles on one symbol, feed, session and timeframe. Compare the Data Window on identical completed timestamps; synthetic candle prices change the inputs.
  • The first baseline bar has no plotted result. The example carries q across a zero-range bar and does not reset the cumulative line each session.
  • Changing loaded history can shift the cumulative baseline. Compare contributions first; then align the accumulation start before comparing S or its averages.
  • Closed-bar confirmation avoids treating a temporary intrabar value as final. It does not correct source data revisions, remove trading costs or prove an edge.
Original audit implementation of the stated formula and policies. Pineify syntax checking does not establish chart parity or trading performance.pine
//@version=6
indicator("VQI arithmetic audit", overlay=false, precision=6)
// Formula reference: LazyBear, Volatility Quality Index [VQI], TradingView.
// Threshold and baseline policy are the explicit research choices on this page.
threshold = input.float(0.05, "Contribution threshold (price units)", minval=0.0)
ready = not na(open) and not na(high) and not na(low) and not na(close) and not na(close[1])
span = high - low
trueSpan = math.max(span, math.max(math.abs(high - close[1]), math.abs(low - close[1])))
var float quality = 0.0
if ready and span > 0 and trueSpan > 0
    quality := ((close - close[1]) / trueSpan + (close - open) / span) / 2.0
float contribution = ready ? math.abs(quality) * (2.0 * close - close[1] - open) / 2.0 : na
var float cumulative = 0.0
if ready
    cumulative += contribution
int direction = ready ? (contribution > threshold ? 1 : contribution < -threshold ? -1 : 0) : 0
visible = ready and barstate.isconfirmed
plot(visible ? cumulative : na, "Cumulative VQI", color=color.blue, linewidth=2, style=plot.style_linebr)
plot(visible ? quality : na, "q", display=display.data_window)
plot(visible ? contribution : na, "Contribution d", display=display.data_window)
plot(visible ? direction : na, "Threshold state", display=display.data_window)
startsUp = visible and ready[1] and direction == 1 and direction[1] != 1
alertcondition(startsUp, "Confirmed upward state starts", "VQI contribution entered the upward threshold state on a completed bar.")

Give Pineify an explicit calculation specification

The Pine Script AI Coding Agent can draft or revise an indicator from these public rules. Include the selected author reference, OHLC inputs, q carry rule, cumulative baseline and threshold units. Ask for separate intermediate plots and request syntax checking explicitly. Compare completed-bar values in TradingView before creating alerts.

  • Keep the gap and zero-range fixtures when adding smoothing. A match on an ordinary upward candle does not cover those boundaries.
  • If converting the state into a strategy, define entries, exits, position size, costs and execution timing separately. This indicator supplies no tested return or risk estimate.
  • Source access and licensing govern reuse. This workflow does not recover a protected indicator's undisclosed algorithm.
Where Pineify fits

Pine Script AI Coding Agent

Draft a VQI calculation from explicit public rules, request syntax checking and compare its intermediate values in TradingView.

Draft a VQI indicator

Frequently asked questions

Educational information, not investment advice. All numerical fixtures are synthetic. Indicator labels, filtered states and accepted code syntax do not establish a trading edge or guarantee returns.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.