Explainers / Dynamic Swing Anchored VWAP
Dynamic Swing Anchored VWAP, explained from the source
Dynamic Swing Anchored VWAP is an open-source TradingView script by Zeiierman (about 16,200 boosts, and one of the most-boosted public scripts of 2025). It marks swing highs and lows with HH, HL, LH and LL labels and draws a volume-weighted line that restarts from each new swing. This page walks through its published code in order, says what each part does, and ends with where it fails. It does not say what any line or label will do next.
The surprise: it is not a classic anchored VWAP
A classic anchored VWAP adds up price times volume from the anchor bar onward and divides by total volume, so the first bar after the anchor counts as much as the latest one. This script does something different. From the anchor it runs an exponentially weighted average of price times volume and of volume, with a half-life set by the Adaptive Price Tracking input (default 20 bars). After 20 bars the anchor's weight has halved; after 60 bars it is down to an eighth. The line is anchored where it starts, and then it slowly forgets the anchor.
Step 1: the swing switch
With the default Swing Period of 50, the script asks on every bar: is this bar's high the highest of the last 50 bars, and is this bar's low the lowest of the last 50? It remembers the bar and price of the latest such high and the latest such low. If the latest 50-bar high came after the latest 50-bar low, direction is up; otherwise it is down. There is no waiting for confirmation and no look into the future: direction changes on the bar where price makes a new 50-bar extreme on the other side.
Step 2: where the line is anchored
When direction turns up, the anchor is the bar of the latest 50-bar low, and its price is that low. When direction turns down, the anchor is the latest 50-bar high. That anchor bar is in the past. The label (HH, HL, LH or LL) is placed on it, comparing the new swing with the previous swing of the same kind.
Step 3: the line is rebuilt from the anchor
On the bar where direction changes, the script starts the sum at the anchor using the swing price times that bar's volume, then walks forward bar by bar to the current bar, blending in each bar's typical price (high plus low plus close, divided by three) weighted by its volume. That whole stretch is drawn at once as a polyline. From then on, each new bar adds one point. When direction changes again, the finished stretch is left on the chart and a new one starts from the new anchor.
Step 4: the half-life input
Adaptive Price Tracking is a half-life in bars, turned into a blend weight of about 3.4% per bar at the default 20. Lower values hug price, higher values move slowly. If you switch on "Adapt APT by ATR ratio", the half-life is divided by the ratio of the 50-bar ATR to its own 50-bar average, raised to the power of Volatility Bias (default 10), then held between 5 and 300 bars. When recent ranges are wider than usual the line speeds up; when they are narrower it slows down.
Step 5: what you see on the chart
HH, HL, LH and LL labels at the swing bars, and one coloured line per swing stretch. There is no table, no score and no alert.
What the settings change
Swing Period sets how many bars a high or low must beat, so a larger number gives fewer, later switches. Adaptive Price Tracking sets the half-life. The ATR switch and Volatility Bias make that half-life move with recent ranges. The colours and line width change only appearance.
What we checked in Python
We ported the swing switch, the weighted line and the ATR-based half-life to Python and ran them on invented random-walk prices (3,000 bars, three seeds, stand-in highs, lows and volumes). Direction changed 33 to 39 times in 2,950 bars, so a stretch lasted a median of 59 to 85 bars. The median distance from the anchor bar back in the past to the bar where its line first appeared was 23 to 24 bars, and up to 75. At the end of each stretch, the script's line sat a median 1.1% to 1.3% of price away from a plain cumulative anchored VWAP started at the same bar. With the ATR switch on and the default bias of 10, the half-life ranged from about 8 bars to about 48 bars for most of the run. These figures describe the code on invented data, not any market.
Where it fails
- The line appears late and is drawn backward. The anchor is a swing low or high that is only known once price makes a new 50-bar extreme on the other side. On invented prices that took a median 23 bars. In history the line starts exactly at the turn; in real time nothing was drawn there until those bars had passed.
- The labels are placed back in time too. An HL or LH label sits on the swing bar, but it was added on the later bar when direction changed. Scrolling back shows every label in a place it could not have been on the day.
- Not the anchored VWAP you may expect. The half-life weighting means it can differ from a classic anchored VWAP from the same bar; on invented prices the gap at the end of a stretch was about 1.1% to 1.3% of price. Compare it with a classic one before treating its touches as the same thing.
- The anchor bar counts twice. The sum starts with the swing price times the anchor bar's volume, and the forward walk then adds the anchor bar's typical price and volume again.
- A switch is a new 50-bar extreme, not a reversal. Direction flips the first time price makes a new 50-bar high after a 50-bar low, even by a tick. In a sideways range that can happen at both edges in turn.
- The colours look swapped against the settings text. Reading the code, the live stretch uses the "downtrend" colour while direction is up and the "uptrend" colour while it is down, and the first bar of each new stretch briefly shows the other colour. This page read that from the code and did not check it on a chart.
- Volume is required. On symbols with no volume data the weighted line has nothing to divide by and does not draw.
- Old stretches drop off. The script allows 100 polylines, so on long histories the oldest stretches are removed.
- The ATR switch is very sensitive. With a bias of 10, a range 10% wider than usual cuts the half-life by more than half, and 10% narrower nearly triples it.
- No alerts and no backtest. The code defines no alert conditions and measures nothing after a switch.
- Open and licensed. The code carries a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 notice and credits Zeiierman; this page describes it in our own words and pastes none of it.
Also explained: Breakout Probability (Expo) · VWAP · Machine Learning Adaptive SuperTrend · Liquidity Swings [LuxAlgo] · Repainting
Educational only. Not financial advice. Nothing here is a recommendation to buy or sell anything. Dynamic Swing Anchored VWAP is by Zeiierman on TradingView and carries a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 notice; this page describes its published open-source code in our own words and is not affiliated with the author. Simulation figures come from synthetic random-walk prices and say nothing about how the script trades.
Also explained: Repaint checker, VWAP, Supertrend, RSI, UT Bot Alerts, Nadaraya-Watson Envelope, Squeeze Momentum, What is repainting on TradingView?, Is TradingView backtesting accurate?, Chandelier Exit, WaveTrend Oscillator, QQE MOD, Pivot highs and lows, Hull Suite, Range Filter, Twin Range Filter, HalfTrend, ZigZag++, SSL Hybrid, CM MacD Ultimate MTF, Volume Profile / Fixed Range, ADX and DI, Support Resistance Channels, Market Structure Break & Order Block, Order Block Finder, Pivot Point SuperTrend, Trendlines with Breaks [LuxAlgo], Divergence for Many Indicators, TradingView script selling terms, Support and Resistance Levels with Break, Liquidity Swings [LuxAlgo], Pine Script errors, Breakout Probability (Expo), Did ChatGPT or Claude write your Pine Sc, Lorentzian Classification, SuperTrend AI (Clustering), Machine Learning Adaptive SuperTrend, Support and Resistance Power Channel by , Support and Resistance (High Volume Boxe, Trendline Breakouts With Targets by Char, Breakout Finder by LonesomeTheBlue
Get the next teardown by email
One short email when a new teardown or free tool goes live, about twice a month. No signals, no hype. Unsubscribe in one click.
Almost done. Check your inbox and click the confirmation link.
Sent with Kit. Your address is used only for these emails. Privacy
No TradingView account yet? This affiliate link gives you a $15 coupon toward a paid plan, and we earn a commission if you buy one. The free plan is enough to follow this page.