OPEN-SOURCE SCRIPT
VWAP Deviation Trend [BackQuant]

VWAP Deviation Trend [BackQuant]
Overview
VWAP Deviation Trend is a volume-weighted trend-following overlay that transforms VWAP and its surrounding price distribution into a directional trailing structure.
Rather than using VWAP only as a fair-value line, the indicator calculates:
The indicator is designed to identify when price has moved far enough away from accepted volume-weighted value to establish a meaningful directional shift.
Unlike a simple VWAP crossover, price can move through VWAP without immediately changing the active trend. A new regime requires price to break the opposite trailing deviation boundary, optionally with confirmation from the direction of VWAP itself.
The updated visual engine also measures trend strength and uses it to control:
Core concept
VWAP represents the average price paid over a selected period, weighted by trading volume.
The basic formula is:
Prices associated with greater volume contribute more heavily to the final value. This makes VWAP a useful approximation of:
However, VWAP alone does not explain how widely price has been distributed around that value.
VWAP Deviation Trend treats VWAP as the center of a volume-weighted price distribution and measures the dispersion around it. That dispersion is then used to create trailing trend boundaries.
VWAP calculation modes
The indicator supports five VWAP windows:
4 Hours
Resets VWAP at fixed four-hour intervals.
This can be useful for:
Daily
Resets at the beginning of each calendar day.
This is the traditional intraday VWAP structure and is useful for:
Weekly
Accumulates volume and price across the current week.
This creates a slower structural anchor suited to:
Rolling Lookback Bars
Calculates VWAP over a fixed number of candles.
The window moves forward continuously and does not reset at a calendar boundary.
This is useful for:
Rolling Lookback Days
Includes bars that fall within a selected number of calendar days.
This keeps the analytical window tied to elapsed time instead of a fixed candle count.
Anchored versus rolling VWAP
Anchored modes begin at a fixed boundary and accumulate until the next reset.
Rolling modes continually remove old observations as new observations arrive.
Anchored VWAP is useful when a particular session or week has structural meaning. Rolling VWAP is useful when the trader wants a stable and continuously adapting lookback.
Volume-weighted deviation
The indicator calculates more than the VWAP mean.
It also measures volume-weighted price variance using:
This measures how widely prices associated with meaningful trading volume are distributed around VWAP.
A small deviation suggests:
A large deviation suggests:
Because the calculation is volume weighted, high-volume prices influence the bands more than low-volume excursions.
Fallback when volume is unavailable
If usable volume is not available, the indicator falls back to an unweighted arithmetic mean and variance.
This allows it to function on synthetic or limited-volume symbols, although the result should then be interpreted as a rolling or anchored mean rather than a true VWAP.
Deviation bands
The raw width is calculated as:
The upper and lower raw bands are:
Higher deviation multipliers create wider bands and fewer trend changes.
Lower multipliers create tighter bands and faster, more frequent flips.
ATR minimum width
During low-dispersion periods, volume-weighted deviation can become extremely narrow.
This can cause small and insignificant movements to trigger repeated reversals.
The optional ATR floor calculates:
The final width becomes:
This preserves volume-weighted deviation as the primary band engine while preventing the channel from collapsing below a practical volatility threshold.
Trailing-band construction
The raw deviation bands move freely with VWAP and dispersion.
The indicator converts them into one-sided trailing levels.
Lower trail
While the selected trigger remains above the lower trail:
This creates a ratcheting support structure.
Upper trail
While the trigger remains below the upper trail:
This creates a ratcheting resistance structure.
The active trend trail is:
Why trailing logic matters
A raw VWAP band can move toward price and create unstable signals.
The one-sided trail preserves trend structure and creates hysteresis.
Hysteresis means the threshold required to enter a bullish regime is different from the threshold required to enter a bearish regime.
This allows price to rotate around VWAP without constantly changing the active trend.
Trend initialization
When the first valid VWAP is available:
After initialization, a full break of the opposite trail is required to change regimes.
Bullish trend flip
A bullish flip requires:
Once confirmed:
Bearish trend flip
A bearish flip requires:
Once confirmed:
Flip trigger
The trend can be triggered using:
Close is the more conventional option.
Using the price source, such as HLC3, can produce a slightly smoother trigger because it reflects more of the bar than the close alone.
VWAP slope confirmation
Optional slope confirmation requires VWAP itself to move in the direction of the proposed new trend.
For a bullish flip:
For a bearish flip:
This can help reject:
The tradeoff is additional confirmation delay.
Breaking the trail on flips
The active trail changes from one side of the market to the other during a regime transition.
The Break Trail On Flips option inserts a visual gap on the flip bar so the previous and new trails are not connected by a misleading line segment.
This affects presentation only.
Visual trend-strength engine
The updated script includes a visual-strength model that controls the intensity of the gradient and glow.
It combines two measurements:
Distance strength
The script measures:
This is normalized by the current band width.
A larger distance indicates stronger separation between price and the structural trail.
Slope strength
VWAP movement across the slope lookback is also normalized by the band width.
This measures whether volume-weighted fair value itself is moving meaningfully relative to the size of the current deviation structure.
Combined trend strength
The final visual strength is weighted:
This produces a value between zero and one.
It does not change trend logic or signals. It controls the visual intensity of the indicator.
Layered gradient fill
Instead of using one flat gradient, the updated indicator divides the space between the trail and price into six visual layers.
The levels are placed progressively between:
The gradient is:
The opacity adapts to trend strength.
When price is strongly separated from the trail and VWAP is moving with the regime:
When the trend is weak:
This makes the visual ribbon encode more than direction. It also reflects the current strength of the price-to-structure relationship.
Flip bloom
After a confirmed trend flip, the indicator creates a temporary bloom around the new trail.
The bloom is strongest immediately after the transition and fades over the following bars.
Its intensity follows this general sequence:
This visually emphasizes fresh regime changes without permanently increasing chart brightness.
The bloom is cosmetic and does not affect calculation.
Adaptive trail glow
The glow surrounding the trail also changes with trend strength.
The base width is ATR-scaled, then increases slightly as the visual trend-strength score rises.
This creates:
The glow contains:
Visual interpretation
The updated presentation provides several pieces of information simultaneously:
How to use the indicator
Trend regime filter
Use the active color and trail position as directional context:
Pullback structure
In a bullish regime:
In a bearish regime:
Trend-strength context
A vivid gradient and broader glow suggest:
A weak or faded gradient suggests:
Fresh transitions
The bloom helps identify newly established regimes.
A fresh flip with:
generally represents stronger early trend structure than a flip that immediately loses visual intensity.
Dynamic risk management
The active trail may be used as:
Because the trail responds to both volume-weighted dispersion and volatility, it adjusts as market conditions change.
How this differs from a standard VWAP
A standard VWAP:
VWAP Deviation Trend:
How this differs from Supertrend
A traditional Supertrend normally uses a central price such as HL2 and ATR-based bands.
VWAP Deviation Trend uses:
This means the trail responds not only to range volatility, but also to where trading volume has been concentrated.
How this differs from Bollinger Bands
Bollinger Bands normally use:
This indicator uses:
It is therefore a trend-regime model rather than a standard mean-reversion envelope.
Input guide
VWAP Mode
Selects the anchored or rolling calculation window.
Deviation Multiplier
Controls the width of the statistical bands.
Higher values produce wider, slower regimes. Lower values produce tighter and faster regimes.
ATR Minimum Width
Prevents excessive narrowing during compressed conditions.
VWAP Slope Confirmation
Requires volume-weighted fair value to move with the proposed trend.
Flip Trigger
Selects whether close or the chosen price source must cross the trail.
Visual settings
Allow the trader to display:
Strengths
Limitations
Alerts
The indicator includes alerts for:
These represent complete VWAP deviation regime changes, not ordinary crosses of VWAP.
Summary
VWAP Deviation Trend converts volume-weighted fair value and price dispersion into a directional trend trail.
It calculates VWAP over a configurable anchored or rolling window, measures volume-weighted standard deviation around that VWAP, and builds upper and lower deviation bands. An optional ATR floor prevents the structure from becoming excessively narrow during quiet conditions.
The raw bands are transformed into one-sided trails. The lower trail ratchets upward during bullish regimes, while the upper trail ratchets downward during bearish regimes. Trend changes occur only when price breaks the opposite trail, optionally with confirmation from the slope of VWAP.
The updated visual engine measures price separation and VWAP slope to dynamically control the layered gradient, trail glow, and temporary post-flip bloom. This creates a clearer representation of direction, structural strength, and fresh regime transitions without changing the underlying signal logic.
Overview
VWAP Deviation Trend is a volume-weighted trend-following overlay that transforms VWAP and its surrounding price distribution into a directional trailing structure.
Rather than using VWAP only as a fair-value line, the indicator calculates:
- A configurable anchored or rolling VWAP.
- The volume-weighted standard deviation of price around that VWAP.
- Adaptive upper and lower deviation bands.
- One-sided trailing boundaries used to confirm bullish and bearish regimes.
The indicator is designed to identify when price has moved far enough away from accepted volume-weighted value to establish a meaningful directional shift.
Unlike a simple VWAP crossover, price can move through VWAP without immediately changing the active trend. A new regime requires price to break the opposite trailing deviation boundary, optionally with confirmation from the direction of VWAP itself.
The updated visual engine also measures trend strength and uses it to control:
- Gradient intensity.
- Trail glow width.
- Post-flip bloom effects.
- The visual separation between price and the active trail.
Core concept
VWAP represents the average price paid over a selected period, weighted by trading volume.
The basic formula is:
- VWAP = Sum of Price × Volume / Sum of Volume
Prices associated with greater volume contribute more heavily to the final value. This makes VWAP a useful approximation of:
- Volume-weighted fair value.
- The center of traded activity.
- The average position of market participants.
- An institutional execution benchmark.
However, VWAP alone does not explain how widely price has been distributed around that value.
VWAP Deviation Trend treats VWAP as the center of a volume-weighted price distribution and measures the dispersion around it. That dispersion is then used to create trailing trend boundaries.
VWAP calculation modes
The indicator supports five VWAP windows:
- 4 Hours
- Daily
- Weekly
- Rolling Lookback Bars
- Rolling Lookback Days
4 Hours
Resets VWAP at fixed four-hour intervals.
This can be useful for:
- Cryptocurrency markets.
- Intraday futures.
- Continuously traded markets.
- Shorter fair-value regimes.
Daily
Resets at the beginning of each calendar day.
This is the traditional intraday VWAP structure and is useful for:
- Session bias.
- Intraday mean reversion.
- Day-trading trend confirmation.
Weekly
Accumulates volume and price across the current week.
This creates a slower structural anchor suited to:
- Swing trading.
- Weekly positioning.
- Broader accepted-value analysis.
Rolling Lookback Bars
Calculates VWAP over a fixed number of candles.
The window moves forward continuously and does not reset at a calendar boundary.
This is useful for:
- Systematic trend models.
- Consistent multi-timeframe analysis.
- Markets where daily sessions are less important.
Rolling Lookback Days
Includes bars that fall within a selected number of calendar days.
This keeps the analytical window tied to elapsed time instead of a fixed candle count.
Anchored versus rolling VWAP
Anchored modes begin at a fixed boundary and accumulate until the next reset.
Rolling modes continually remove old observations as new observations arrive.
Anchored VWAP is useful when a particular session or week has structural meaning. Rolling VWAP is useful when the trader wants a stable and continuously adapting lookback.
Volume-weighted deviation
The indicator calculates more than the VWAP mean.
It also measures volume-weighted price variance using:
- Weighted Mean Square = Sum of Price² × Volume / Sum of Volume
- Weighted Variance = Weighted Mean Square - VWAP²
- Weighted Deviation = Square Root of Weighted Variance
This measures how widely prices associated with meaningful trading volume are distributed around VWAP.
A small deviation suggests:
- Trading is concentrated near fair value.
- The market is relatively balanced.
- Price acceptance is narrow.
A large deviation suggests:
- Trading is spread across a wider range.
- Price discovery is more active.
- The market is less tightly centered around VWAP.
Because the calculation is volume weighted, high-volume prices influence the bands more than low-volume excursions.
Fallback when volume is unavailable
If usable volume is not available, the indicator falls back to an unweighted arithmetic mean and variance.
This allows it to function on synthetic or limited-volume symbols, although the result should then be interpreted as a rolling or anchored mean rather than a true VWAP.
Deviation bands
The raw width is calculated as:
- Deviation Width = Weighted Deviation × Deviation Multiplier
The upper and lower raw bands are:
- Upper Band = VWAP + Band Width
- Lower Band = VWAP - Band Width
Higher deviation multipliers create wider bands and fewer trend changes.
Lower multipliers create tighter bands and faster, more frequent flips.
ATR minimum width
During low-dispersion periods, volume-weighted deviation can become extremely narrow.
This can cause small and insignificant movements to trigger repeated reversals.
The optional ATR floor calculates:
- ATR Floor = ATR × ATR Minimum Multiplier
The final width becomes:
- Band Width = Maximum of Deviation Width and ATR Floor
This preserves volume-weighted deviation as the primary band engine while preventing the channel from collapsing below a practical volatility threshold.
Trailing-band construction
The raw deviation bands move freely with VWAP and dispersion.
The indicator converts them into one-sided trailing levels.
Lower trail
While the selected trigger remains above the lower trail:
- The trail can rise.
- It cannot move downward.
This creates a ratcheting support structure.
Upper trail
While the trigger remains below the upper trail:
- The trail can fall.
- It cannot move upward.
This creates a ratcheting resistance structure.
The active trend trail is:
- The lower trail during bullish regimes.
- The upper trail during bearish regimes.
Why trailing logic matters
A raw VWAP band can move toward price and create unstable signals.
The one-sided trail preserves trend structure and creates hysteresis.
Hysteresis means the threshold required to enter a bullish regime is different from the threshold required to enter a bearish regime.
This allows price to rotate around VWAP without constantly changing the active trend.
Trend initialization
When the first valid VWAP is available:
- The trend initializes bullish if the trigger is at or above VWAP.
- The trend initializes bearish if the trigger is below VWAP.
After initialization, a full break of the opposite trail is required to change regimes.
Bullish trend flip
A bullish flip requires:
- The selected trigger to move above the upper trailing band.
- The current trend not already to be bullish.
- VWAP slope confirmation to pass if enabled.
Once confirmed:
- The trend becomes bullish.
- The active trail moves beneath the market.
- A bullish signal marker is displayed.
Bearish trend flip
A bearish flip requires:
- The selected trigger to move below the lower trailing band.
- The current trend not already to be bearish.
- VWAP slope confirmation to pass if enabled.
Once confirmed:
- The trend becomes bearish.
- The active trail moves above the market.
- A bearish signal marker is displayed.
Flip trigger
The trend can be triggered using:
- Close
- The selected VWAP price source
Close is the more conventional option.
Using the price source, such as HLC3, can produce a slightly smoother trigger because it reflects more of the bar than the close alone.
VWAP slope confirmation
Optional slope confirmation requires VWAP itself to move in the direction of the proposed new trend.
For a bullish flip:
- Current VWAP must be above VWAP from the selected lookback.
For a bearish flip:
- Current VWAP must be below its prior value.
This can help reject:
- Temporary band breaks.
- Low-volume price spikes.
- Liquidity sweeps against flat fair value.
The tradeoff is additional confirmation delay.
Breaking the trail on flips
The active trail changes from one side of the market to the other during a regime transition.
The Break Trail On Flips option inserts a visual gap on the flip bar so the previous and new trails are not connected by a misleading line segment.
This affects presentation only.
Visual trend-strength engine
The updated script includes a visual-strength model that controls the intensity of the gradient and glow.
It combines two measurements:
- Distance between price and the active trail.
- Slope of VWAP relative to the current band width.
Distance strength
The script measures:
- Absolute Distance = |Close - Trend Trail|
This is normalized by the current band width.
A larger distance indicates stronger separation between price and the structural trail.
Slope strength
VWAP movement across the slope lookback is also normalized by the band width.
This measures whether volume-weighted fair value itself is moving meaningfully relative to the size of the current deviation structure.
Combined trend strength
The final visual strength is weighted:
- 70% price-to-trail distance.
- 30% VWAP slope strength.
This produces a value between zero and one.
It does not change trend logic or signals. It controls the visual intensity of the indicator.
Layered gradient fill
Instead of using one flat gradient, the updated indicator divides the space between the trail and price into six visual layers.
The levels are placed progressively between:
- The active trend trail.
- The current closing price.
The gradient is:
- Most concentrated near the structural trail.
- Progressively softer toward price.
The opacity adapts to trend strength.
When price is strongly separated from the trail and VWAP is moving with the regime:
- The gradient becomes more vivid.
When the trend is weak:
- The fill becomes softer and more transparent.
This makes the visual ribbon encode more than direction. It also reflects the current strength of the price-to-structure relationship.
Flip bloom
After a confirmed trend flip, the indicator creates a temporary bloom around the new trail.
The bloom is strongest immediately after the transition and fades over the following bars.
Its intensity follows this general sequence:
- First bar after flip: strongest bloom.
- Second bar: reduced bloom.
- Third bar: light residual bloom.
- Afterward: bloom disappears.
This visually emphasizes fresh regime changes without permanently increasing chart brightness.
The bloom is cosmetic and does not affect calculation.
Adaptive trail glow
The glow surrounding the trail also changes with trend strength.
The base width is ATR-scaled, then increases slightly as the visual trend-strength score rises.
This creates:
- A broader glow during stronger regimes.
- A narrower glow when trend structure is weaker.
The glow contains:
- An inner, more visible layer.
- A wider, softer outer layer.
Visual interpretation
The updated presentation provides several pieces of information simultaneously:
- Color shows the active trend direction.
- The trail shows the structural regime boundary.
- Gradient intensity reflects trend strength.
- Glow width reinforces structural conviction.
- The bloom highlights fresh regime transitions.
How to use the indicator
Trend regime filter
Use the active color and trail position as directional context:
- Favor longs during bullish regimes.
- Favor shorts during bearish regimes.
Pullback structure
In a bullish regime:
- VWAP represents volume-weighted fair value.
- The lower trail represents deeper structural support.
In a bearish regime:
- VWAP represents the mean-reversion anchor.
- The upper trail represents deeper structural resistance.
Trend-strength context
A vivid gradient and broader glow suggest:
- Price is well separated from the trail.
- VWAP is moving in the trend direction.
- The regime has stronger structural momentum.
A weak or faded gradient suggests:
- Price is closer to the trail.
- VWAP slope is weaker.
- The trend may be consolidating or losing strength.
Fresh transitions
The bloom helps identify newly established regimes.
A fresh flip with:
- Strong bloom.
- Growing price separation.
- VWAP slope alignment.
generally represents stronger early trend structure than a flip that immediately loses visual intensity.
Dynamic risk management
The active trail may be used as:
- A trailing stop reference.
- A regime invalidation boundary.
- A position-management guide.
Because the trail responds to both volume-weighted dispersion and volatility, it adjusts as market conditions change.
How this differs from a standard VWAP
A standard VWAP:
- Plots only volume-weighted mean price.
- Usually resets once per session.
- Does not maintain trend state.
VWAP Deviation Trend:
- Supports anchored and rolling windows.
- Calculates volume-weighted dispersion.
- Creates adaptive raw bands.
- Converts them into directional trailing boundaries.
- Maintains persistent bullish and bearish regimes.
- Adds a strength-reactive visual system.
How this differs from Supertrend
A traditional Supertrend normally uses a central price such as HL2 and ATR-based bands.
VWAP Deviation Trend uses:
- Volume-weighted fair value as the center.
- Volume-weighted standard deviation as the primary width.
- ATR only as an optional minimum floor.
This means the trail responds not only to range volatility, but also to where trading volume has been concentrated.
How this differs from Bollinger Bands
Bollinger Bands normally use:
- A moving average.
- Unweighted standard deviation.
- Symmetrical non-trailing bands.
This indicator uses:
- A volume-weighted mean.
- Volume-weighted variance.
- One-sided trailing bands.
- Persistent trend-state logic.
It is therefore a trend-regime model rather than a standard mean-reversion envelope.
Input guide
VWAP Mode
Selects the anchored or rolling calculation window.
Deviation Multiplier
Controls the width of the statistical bands.
Higher values produce wider, slower regimes. Lower values produce tighter and faster regimes.
ATR Minimum Width
Prevents excessive narrowing during compressed conditions.
VWAP Slope Confirmation
Requires volume-weighted fair value to move with the proposed trend.
Flip Trigger
Selects whether close or the chosen price source must cross the trail.
Visual settings
Allow the trader to display:
- The trend trail.
- VWAP.
- Raw deviation bands.
- Layered gradient.
- Adaptive glow.
- Signals.
- Trend candles.
Strengths
- Combines fair value, dispersion, and trend structure.
- Uses volume-weighted mean and variance.
- Supports multiple anchored and rolling VWAP windows.
- Uses ATR protection against narrow-band whipsaws.
- Creates persistent regimes with hysteresis.
- Provides optional VWAP slope confirmation.
- Includes a trend-strength-reactive visual system.
- Clearly emphasizes fresh trend transitions.
Limitations
- Volume quality varies between instruments.
- Anchored VWAP modes may be unstable immediately after a reset.
- Long windows can react slowly to sudden regime changes.
- Tight settings can increase whipsaws.
- Wide settings can delay reversals.
- Slope confirmation can add additional lag.
- Visual strength is contextual and is not a separate trading signal.
Alerts
The indicator includes alerts for:
- Confirmed bullish trend flips.
- Confirmed bearish trend flips.
These represent complete VWAP deviation regime changes, not ordinary crosses of VWAP.
Summary
VWAP Deviation Trend converts volume-weighted fair value and price dispersion into a directional trend trail.
It calculates VWAP over a configurable anchored or rolling window, measures volume-weighted standard deviation around that VWAP, and builds upper and lower deviation bands. An optional ATR floor prevents the structure from becoming excessively narrow during quiet conditions.
The raw bands are transformed into one-sided trails. The lower trail ratchets upward during bullish regimes, while the upper trail ratchets downward during bearish regimes. Trend changes occur only when price breaks the opposite trail, optionally with confirmation from the slope of VWAP.
The updated visual engine measures price separation and VWAP slope to dynamically control the layered gradient, trail glow, and temporary post-flip bloom. This creates a clearer representation of direction, structural strength, and fresh regime transitions without changing the underlying signal logic.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Check out whop.com/signals-suite for Access to Invite Only Scripts!
Or go to backquant.com/
Or go to backquant.com/
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.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Check out whop.com/signals-suite for Access to Invite Only Scripts!
Or go to backquant.com/
Or go to backquant.com/
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.