OPEN-SOURCE SCRIPT
Dynamic Swing Anchored VWAP STRAT (Zeiierman/PineIndicators)

Dynamic Swing Anchored VWAP STRATEGY — Zeiierman × PineIndicators (Pine Script v6)
A pivot-to-pivot Anchored VWAP strategy that adapts to volatility, enters long on bullish structure, and closes on bearish structure. Built for TradingView in Pine Script v6.
Full credits to zeiierman.
Concept
How it works (under the hood)
Inputs & controls
Trade logic summary
Recommended workflow
Practical tips
Extending the script (ideas)
Known limitations
Defaults (backtest environment)
Quick checklist
Attribution & license
A pivot-to-pivot Anchored VWAP strategy that adapts to volatility, enters long on bullish structure, and closes on bearish structure. Built for TradingView in Pine Script v6.
Full credits to zeiierman.
Repainting notice: The original indicator logic is repainting. Swing labels (HH/HL/LH/LL) are finalized after enough bars have printed, so labels do not occur in real time. It is not possible to execute at historical label points. Treat results as educational and validate with Bar Replay and paper trading before considering any discretionary use.
Concept
- The script identifies swing highs/lows over a user-defined lookback (Swing Period). When structure flips (most recent swing low is newer than the most recent swing high, or vice versa), a new regime begins.
- At each confirmed pivot, a fresh Anchored VWAP segment is started and updated bar-by-bar using an EWMA-style decay on price×volume and volume.
- Responsiveness is controlled by Adaptive Price Tracking (APT). Optionally, APT auto-adjusts with an ATR ratio so that high volatility accelerates responsiveness and low volatility smooths it.
- Longs are opened/held in bullish regimes and closed when the regime turns bearish. No short positions are taken by design.
How it works (under the hood)
- Swing detection: Uses ta.highestbars/ta.lowestbars over prd to update swing highs (ph) and lows (pl), plus their bar indices (phL, plL).
- Regime logic: If phL > plL → bullish regime; else → bearish regime. A change in this condition triggers a re-anchor of the VWAP at the newest pivot.
- Adaptive VWAP math: APT is converted to an exponential decay factor (alphaFromAPT), then applied to running sums of price×volume and volume, producing the current VWAP estimate.
- Rendering: Each pivot-anchored VWAP segment is drawn as a polyline and color-coded by regime. Optional structure labels (HH/HL/LH/LL) annotate the swing character.
- Orders: On bullish flips, strategy.entry("L") opens/maintains a long; on bearish flips, strategy.close("L") exits.
Inputs & controls
- Swing Period (prd) — Higher values identify larger, slower swings; lower values catch more frequent pivots but add noise.
- Adaptive Price Tracking (APT) — Governs the VWAP’s “half-life.” Smaller APT → faster/closer to price; larger APT → smoother/stabler.
- Adapt APT by ATR ratio — When enabled, APT scales with volatility so the VWAP speeds up in turbulent markets and slows down in quiet markets.
- Volatility Bias — Tunes the strength of APT’s response to volatility (above 1 = stronger effect; below 1 = milder).
- Style settings — Colors for swing labels and VWAP segments, plus line width for visibility.
Trade logic summary
- Entry: Long when the swing structure turns bullish (latest swing low is more recent than the last swing high).
- Exit: Close the long when structure turns bearish.
- Position size:qty = strategy.equity / close × 5 (dynamic sizing; scales with account equity and instrument price). Consider reducing the multiplier for a more conservative profile.
Recommended workflow
- Apply to instruments with reliable volume (equities, futures, crypto; FX tick volume can work but varies by broker).
- Start on your preferred timeframe. Intraday often benefits from smaller APT (more reactive); higher timeframes may prefer larger APT (smoother).
- Begin with defaults (prd=50, APT=20); then toggle “Adapt by ATR” and vary Volatility Bias to observe how segments tighten/loosen.
- Use Bar Replay to watch how pivots confirm and how the strategy re-anchors VWAP at those confirmations.
- Layer your own risk rules (stops/targets, max position cap, session filters) before any discretionary use.
Practical tips
- Context filter: Consider combining with a higher-timeframe bias (e.g., daily trend) and using this strategy as an entry timing layer.
- First pivot preference: Some traders prefer only the first bullish pivot after a bearish regime (and vice versa) to reduce whipsaw in choppy ranges.
- Deviations: You can add VWAP deviation bands to pre-plan partial exits or re-entries on mean-reversion pulls.
- Sessions: Session-based filters (RTH vs. ETH) can materially change behavior on futures and equities.
Extending the script (ideas)
- Add stops/targets (e.g., ATR stop below last swing low; partial profits at k×VWAP deviation).
- Introduce mirrored short logic for two-sided testing.
- Include alert conditions for regime flips or for price-VWAP interactions.
- Incorporate HTF confirmation (e.g., only long when daily VWAP slope ≥ 0).
- Throttle entries (e.g., once per regime flip) to avoid over-trading in ranges.
Known limitations
- Repainting: Swing labels and pivot confirmations depend on future bars; historical labels can look “perfect.” Treat them as annotations, not executable signals.
- Execution realism: Strategy includes commission and slippage fields, yet actual fills differ by venue/liquidity.
- No guarantees: Past behavior does not imply future results. This publication is for research/education only and not financial advice.
Defaults (backtest environment)
- Initial capital: 10,000
- Commission value: 0.01
- Slippage: 1
- Overlay: true
- Max bars back: 5000; Max labels/polylines set for deep swing histories
Quick checklist
- Add to chart and verify that the instrument has volume.
- Use defaults, then tune APT and Volatility Bias with/without ATR adaptation.
- Observe how each pivot re-anchors VWAP and how regime flips drive entries/exits.
- Paper trade across several symbols/timeframes before any discretionary decisions.
Attribution & license
- Original indicator concept and logic: Zeiierman — please credit the author.
- Strategy wrapper and publication: PineIndicators.
- License: CC BY-NC-SA 4.0 (Attribution-NonCommercial-ShareAlike). Respect the license when forking or publishing derivatives.
Script open-source
Dans l'esprit de TradingView, le créateur de ce script l'a rendu open-source, afin que les traders puissent examiner et vérifier sa fonctionnalité. Bravo à l'auteur! Vous pouvez l'utiliser gratuitement, mais n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script open-source
Dans l'esprit de TradingView, le créateur de ce script l'a rendu open-source, afin que les traders puissent examiner et vérifier sa fonctionnalité. Bravo à l'auteur! Vous pouvez l'utiliser gratuitement, mais n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.