OPEN-SOURCE SCRIPT

Volatility Gated Supertrend [BackQuant]

20 662
Volatility Gated Supertrend [BackQuant]

Overview
Volatility Gated Supertrend is a regime-aware trend-following indicator built around a modified Supertrend engine with an integrated volatility filter. Unlike a traditional Supertrend, which flips direction whenever price crosses its trailing bands, this version introduces a gating mechanism that can block trend reversals during low-volatility conditions.

The purpose of the indicator is simple:
  • Keep the responsiveness and structure of a Supertrend.
  • Reduce false flips during sideways or compressed conditions.
  • Allow trend transitions primarily when volatility is expanding enough to justify participation.


The result is a smoother and more selective trend engine designed to suppress whipsaws while still reacting to meaningful directional movement.

The full source structure for the indicator can be referenced here: :contentReference[oaicite:0]{index=0}

Core idea
Traditional Supertrend indicators work well during directional markets but struggle in compressed environments:
  • Price repeatedly crosses the trailing bands.
  • Trend direction flips too frequently.
  • False reversals appear during chop.


This indicator attempts to solve that problem by asking:
  • “Is there enough volatility expansion to justify accepting a new trend?”


Instead of blindly allowing every flip, the indicator measures:
  • Current volatility,
  • Baseline volatility,
  • Relative expansion or compression.


Only when volatility conditions are sufficient does the trend engine allow a directional transition.

What the Supertrend is
The Supertrend is a volatility-based trailing trend indicator built from:
  • ATR (Average True Range)
  • A central price source
  • A directional trailing stop structure


The classic logic:
  • Upper band = price source + ATR × multiplier
  • Lower band = price source − ATR × multiplier


These bands trail price dynamically:
  • In bullish conditions, the lower band ratchets upward.
  • In bearish conditions, the upper band ratchets downward.


When price crosses one of the bands:
  • The trend flips direction.


This creates a clean directional regime model.

How this version differs
The major difference is the volatility gate.

A normal Supertrend asks:
  • “Did price cross the band?”


This indicator asks:
  • “Did price cross the band, and is volatility strong enough to trust the move?”


That additional filter dramatically changes behavior in sideways conditions.

ATR and volatility structure
The indicator uses two ATR measurements:
  • Fast ATR → current short-term volatility
  • Slow ATR → baseline long-term volatility


The core ratio:
  • Volatility Ratio = Fast ATR / Slow ATR


Interpretation:
  • Ratio above threshold → volatility expansion
  • Ratio below threshold → volatility compression


This becomes the gate logic.

Volatility Gate Logic
The gate opens only when:
  • Fast ATR / Slow ATR ≥ Gate Threshold


If volatility is too compressed:
  • The gate closes.
  • Trend flips are blocked.


Importantly:
  • The Supertrend bands still calculate normally.
  • Price can still cross them.
  • But the directional state will not update while the gate is closed.


This distinction matters because it means:
  • The market may technically trigger a reversal,
  • But the indicator intentionally ignores it if volatility conditions are weak.


Why this helps
Most trend-following systems fail in chop because:
  • Small meaningless moves trigger directional flips.
  • There is insufficient range expansion.
  • The market lacks trend persistence.


By requiring volatility confirmation:
  • Weak reversals are filtered out.
  • Trend state becomes more stable.
  • Noise is reduced.


This makes the indicator particularly useful during:
  • Low-volatility consolidations,
  • Mean-reverting conditions,
  • Slow drifting ranges.


Band construction
The indicator uses:
  • hl2 as the central source,
  • ATR for dynamic width,
  • A configurable multiplier for sensitivity.


Formulas:
  • Upper Band = hl2 + ATR × multiplier
  • Lower Band = hl2 − ATR × multiplier


The trailing logic prevents the bands from moving backward unnecessarily:
  • Bullish lower band only rises.
  • Bearish upper band only falls.


This creates the staircase-style trailing structure common in Supertrend systems.

Trend state
Trend direction is binary:
  • 1 = bullish
  • -1 = bearish


A raw bullish flip occurs when:
  • Close > trailing upper band


A raw bearish flip occurs when:
  • Close < trailing lower band


However:
  • The trend only updates if the volatility gate is open.


This is the defining behavior of the script.

Blocked flips
One of the most important features is the visualization of blocked signals.

When:
  • Price crosses a band,
  • But volatility is insufficient,


The script:
  • Plots an X-cross marker,
  • Keeps the existing trend state,
  • Refuses the flip.


This gives traders visibility into:
  • Potential but unconfirmed reversals,
  • Areas of weak participation,
  • Fake breakouts or low-energy transitions.


Visual behavior

Trend band
The active trailing band changes color based on trend direction:
  • Bullish → bullish color
  • Bearish → bearish color
  • Gate closed → gated color (dimmed)


Trend fill
The script fills the space between price and the active band:
  • Bullish fill during bullish regimes
  • Bearish fill during bearish regimes


This creates a cleaner directional overlay.

Outer glow
An additional glow layer expands slightly beyond the trend band:
  • Adds directional emphasis,
  • Improves trend readability,
  • Visually reinforces active regime.


When the gate closes:
  • The band and candles dim.


This visually communicates:
  • “The trend engine is currently suppressing flips.”


Candle coloring
Candles can optionally inherit the trend state:
  • Bullish regime → bullish candles
  • Bearish regime → bearish candles
  • Gate closed → dimmed neutral appearance


This allows the indicator to function as a full-chart regime overlay.

Signal logic

Bullish signal
Occurs when:
  • Trend flips from bearish to bullish,
  • AND the gate is open.


Bearish signal
Occurs when:
  • Trend flips from bullish to bearish,
  • AND the gate is open.


Blocked signal
Occurs when:
  • A raw flip condition appears,
  • BUT volatility ratio is below threshold.


This distinction is important:
  • A blocked signal is not ignored information.
  • It is a rejected transition.


How to interpret the gate

Gate open
  • Volatility is active.
  • Market expansion is sufficient.
  • Trend flips are allowed.


Gate closed
  • Market is compressed.
  • Conditions are likely choppy.
  • Trend reversals are suppressed.


This effectively turns the indicator into a:
  • Trend-following system during expansion,
  • Trend-holding system during compression.


Why ATR ratio works well
ATR ratio is a powerful regime detector because it measures:
  • Current volatility relative to normal volatility.


Not just:
  • “Is volatility high?”


But:
  • “Is volatility high relative to its recent baseline?”


This adaptive behavior allows the gate to work across:
  • Different assets,
  • Different timeframes,
  • Different volatility environments.


Input guide

ATR Multiplier
Controls band width:
  • Higher = wider bands, fewer flips
  • Lower = tighter bands, more sensitivity


ATR Length
Controls volatility calculation for the Supertrend itself.

Fast ATR
Short-term volatility measure.

Slow ATR
Long-term baseline volatility measure.

Gate Threshold
Controls how strict the gate is:
  • Lower threshold = more permissive
  • Higher threshold = more restrictive


Example:
  • 0.6 → allows more flips
  • 1.0 → requires current volatility to match baseline
  • 1.2 → requires expansion regime


Strengths
  • Reduces Supertrend whipsaws in chop.
  • Adds regime awareness.
  • Uses adaptive volatility filtering.
  • Clean trend visualization.
  • Blocked-signal logic provides extra context.


Limitations
  • Can delay reversals during early expansion.
  • Very high thresholds may suppress legitimate transitions.
  • Still fundamentally a trend-following system.
  • Not designed for low-volatility mean reversion trading.


Best use case
Volatility Gated Supertrend works best as:
  • A directional regime filter,
  • A swing trend overlay,
  • A volatility-aware trend confirmation tool,
  • A way to suppress noise during consolidations.


It is particularly useful for traders who:
  • Like Supertrend logic,
  • But dislike how often it flips in sideways markets.


Summary
Volatility Gated Supertrend extends the classic Supertrend framework by introducing a volatility-aware gating engine that blocks trend reversals during compressed market conditions. By comparing fast ATR against slow ATR, the script determines whether enough volatility expansion exists to justify a directional transition. The result is a cleaner, more stable trend system that retains the strengths of Supertrend logic while dramatically reducing whipsaws during low-energy market regimes.

Penafian

Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.