OPEN-SOURCE SCRIPT

Stretch z distance from session VWAP

404
What it does

This indicator measures how far price has travelled from the session VWAP and expresses that distance as a normalised score, so the reading means the same thing on a quiet day as on a violent one.

It plots the score in a separate pane with reference bands, and shows a readout of the current value, the band it sits in, the raw distance in points, and where the reading ranks against recent history.

The problem it addresses

Distance from VWAP is a natural thing to watch, but the raw number is not comparable across time or symbols. Ten dollars from VWAP might be an extreme on a quiet gold session and completely ordinary during a high-volatility release. The same is true across instruments: a distance that is stretched on one contract is meaningless on another.

The fix is to divide the distance by a measure of how far price normally sits from VWAP. What comes out is a dimensionless score. A reading of 2 means roughly the same thing regardless of instrument or volatility regime, which makes thresholds portable rather than something you retune every few months.

How it is calculated
z = (price - session VWAP) / dispersion

VWAP is anchored to the session set in the inputs and resets each session.

Dispersion is selectable:

Standard deviation of the spread. The standard deviation of (price - VWAP) over a rolling window. This produces a true z-score, answering how unusual the current distance is compared with how far price normally sits from VWAP on this symbol.
ATR. The daily average true range. This expresses the distance in units of daily range instead. It is easier to reason about in points, but it is not a z-score, and the band thresholds mean something different under it. Pick one convention and stay with it.
The session-anchoring option

This is the part that differs most from a standard VWAP deviation plot, and it is worth understanding before you use the indicator.

A rolling dispersion window carries across the session boundary. At the session open, VWAP resets and the spread collapses toward zero, but the rolling window is still filled with the previous session's much larger spreads. The dispersion estimate is therefore too large in the early session, which makes the score read too small precisely when you are most likely to be looking at it.

The size of the effect depends on your chart timeframe and window length: a 60-bar window on a 5-minute chart does not fully clear the previous session for about five hours.

Switching Anchor the window to the session ON restarts the dispersion estimate at each open and builds it forward. This removes the carry-over. The trade-off is that with only a handful of bars the estimate is noisy, so the first several bars of each session are less reliable in a different way. Neither setting is universally correct; the option exists so you can see the difference on your own charts and choose deliberately rather than inherit an assumption.

The indicator suppresses output while the estimate is still warming up under either setting.

How to use it

Reading the score. Zero means price is at the session VWAP. Positive means above, negative means below. The magnitude is the interesting part: it tells you whether the current distance is normal or unusual for this instrument, rather than merely how far price has moved.

Bands as context, not signals. The bands mark where readings become progressively less common. A reading inside the first band is ordinary. Beyond the second, price is unusually far from where the session has been transacting. Beyond the third, it is far enough that the reading itself is rare. None of these is an instruction to do anything, and the indicator issues no entry or exit signals.

As a filter rather than a trigger. The most straightforward use is as a condition applied to setups you are already trading. Strategies that depend on price being near value behave differently when the score is high, and strategies that depend on price having extended behave differently when it is low. The score gives you a consistent way to describe that condition instead of eyeballing it.

The percentile row. The readout shows where the current absolute reading ranks against the last 500 bars. This separates a reading that is genuinely rare for the symbol from one that merely looks large on the pane. If the score reads 2.5 but the percentile is 80%, that magnitude is common on this instrument and timeframe.

Direction versus magnitude. The sign tells you which side of value price is on; the magnitude tells you how far. These carry different information. Price can be persistently above VWAP with a small score, which describes an orderly trend, or briefly above with a large score, which describes a sharp excursion.

The band scoring table

If you grade setups with a checklist, the optional table maps each band to a point value for up to three named strategies, and shows what the current band is worth to each of them side by side.

This exists because the same reading is not equally meaningful to different approaches. A strategy that enters near value and a strategy that enters after extension will value a high reading very differently, sometimes in opposite directions. Rather than assume one interpretation, the indicator lets you define the mapping yourself.

All twelve point values, and the three strategy names, are inputs. The defaults are placeholders and carry no claim about which values are correct. If you use the table, set the values from your own testing.

Limitations
The score is not predictive. It describes where price currently sits relative to the session's transaction history. It says nothing about what happens next, and an unusual reading can persist for a long time or become more unusual still.

Early-session readings are less reliable under both dispersion settings, for the different reasons described above.

The two normalisers are not interchangeable. Thresholds set under one do not carry over to the other.

The session setting matters. VWAP anchors to it, so an incorrect session for your instrument produces a meaningless spread and therefore a meaningless score.

On very low-volume or illiquid symbols, VWAP itself is unstable, and the score inherits that instability.

The percentile row is relative to the last 500 bars of the chart you are on. Changing timeframe changes what it is comparing against.

The daily ATR is requested with lookahead disabled and uses the previous completed daily bar, so it does not repaint.

Settings

Normaliser - standard deviation of the spread, or ATR.
Rolling window - bars used for the dispersion estimate.
Anchor the window to the session - restart the dispersion estimate at each open.
Daily ATR length - used only when ATR is the normaliser.
Session - the window VWAP anchors to.
Bands - the three reference levels.
Band scoring - optional point mapping for up to three named strategies.
Colours - line, band, shading and table colours.

This indicator is a descriptive tool. It does not generate buy or sell signals and makes no claim about future price movement

Clause de non-responsabilité

Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.