Anchored VWAP in Pine Script
The volume-weighted average price of all trading since a bar you choose, so the line is the running break-even of everyone who has traded since that event.
Definition
Anchored VWAP (AVWAP) is the volume-weighted average price measured from a chosen starting bar forward. Where a session VWAP restarts at every open, an anchored VWAP is pinned to one event: a major swing low or high, an earnings gap, a breakout bar, an IPO day, or the first bar of a year or quarter. From that bar on, every new bar adds its typical price weighted by its volume to a running average, and the line becomes the average price paid by everyone who has traded since the anchor.
That is why the line matters. A moving average summarises price over a fixed window; an anchored VWAP summarises money. While price holds above a rising anchored VWAP, the average participant since the anchor is in profit and a pullback into the line is where that group can defend its break-even. Once price accepts below the line, the same group is under water, and later retests from beneath tend to meet supply from traders who want out at cost. The line is a cohort's position, not an arbitrary level.
The idea descends from Paul Levine's MIDAS studies in the mid-1990s, which launched VWAP curves from reversal points, and was made a general workflow by Brian Shannon, who anchors to the events that most traders remember. In practice the concept has two uses: as a support and resistance line in its own right, and as a stretch gauge that shows how far price has run from the cohort's average cost.
Mechanically the line behaves unlike any horizontal reference because it keeps moving. Every bar folds its volume into the sums, so the level drifts toward where business is being done, and its sensitivity decays as the anchor ages: early on one heavy session can bend the line visibly, months later the accumulated volume makes it slow and stable. A young anchored VWAP hugging price says the market still trades near the cohort's cost; an old, flat one far away is a deep reference that only large moves revisit.
Reading the chart
The line is only as meaningful as its anchor, so identification starts with the event, not with the line.
- Pick the anchor bar: a major swing high or low, an earnings or news gap, the breakout bar of a base, an IPO day, or the first bar of a year, quarter or month. The test is whether a real group of traders measures its position from that event.
- Start the calculation on that bar and let it run forward. Nothing before the anchor enters the sums, so two anchors a few bars apart can give visibly different lines when the first bars carried heavy volume.
- Treat the line as a thin zone rather than an exact tick. Wick tests and close tests differ, and the line itself moves a little every bar.
- Watch the first few interactions. Rejection wicks and defended closes at the line show the cohort protecting its basis; a close through it and a failed retest from the other side puts the role-reversal read in play.
- Note the age of the anchor. A line from last week reacts to today's volume; a line from last year barely moves, and a touch of it is a bigger event.
- Mark confluence. Where the moving line crosses a fixed reference such as the previous day's high, a pivot level or a Fibonacci retracement, the overlap is a stronger zone than either input alone.
The maths
The anchored VWAP at any bar is the sum of price times volume since the anchor, divided by the sum of volume since the anchor.
Typical price is the usual source. Variants use the close, or the average of open, high, low and close.
Session VWAP is the special case with the anchor at the session open; a weekly or monthly VWAP anchors at the first bar of the period.
The bands are the anchored VWAP plus and minus a multiple of the volume-weighted standard deviation, computed from the same sums, so they widen as the cohort's prices spread out.
The line is not a moving average of price: two bars at the same price but different volume pull the line by different amounts.
Inputs that matter
| Input | Typical | What changing it does |
|---|---|---|
| Anchor date | the last major swing, gap or period open | Everything. Move the anchor and you change which cohort's cost the line measures. |
| Source | typical price (hlc3) | Close-based lines sit a little differently on wide-range bars; the difference is small on liquid names. |
| Band deviation | 1 (and 2 for the outer band) | Wider bands mark the outer edge of the cohort's prices; touches there mean price is stretched relative to average cost. |
In practice
- As trend pullback support: anchor at the event that started the move (a major low, a gap, a high-volume news bar) and watch the first returns to the line for defended tests. It is the volume-aware cousin of a moving average acting as dynamic support.
- As a polarity line: once price accepts below an anchored VWAP from a significant low, retests from underneath are treated as resistance, and a later reclaim of the line is watched as an early repair signal.
- As a two-sided bracket: anchors from the last major high and the last major low frame the current auction, and compression between the two lines sets up the resolution trade.
- As confluence: where the developing line crosses a horizontal reference such as a prior period level or a high-volume node, the overlap is treated as a stronger zone than either reference alone.
- As standing references: a small set of always-on anchors from the year open, the quarter open and the last major pivot gives every chart a consistent frame.
- As a stretch gauge: the distance from the line, in band units, shows how far price has run from the cohort's average cost, which helps judge late entries and frames fade-back-to-the-line ideas in ranging conditions.
Where it goes wrong
- Anchoring to a bar nobody cares about. If the anchor is not an event traders remember, the line measures a cohort that does not exist as a group; anchor to swings, gaps and period opens.
- Reading one touch as proof. A single tag of the line is a data point; a defended close and a failed retest from the other side are the evidence.
- Trading the line on illiquid charts. When volume is thin or erratic, one print can bend a young line; use daily bars or a liquid market, or wait for the anchor to age.
- Forgetting the line moves. Alerts set at today's value are stale tomorrow; use a script that alerts on the cross of the live line.
Compared with
VWAP. Session VWAP re-anchors automatically at every open, so its cohort resets daily; an anchored VWAP is pinned to one chosen event and carries that cohort's cost basis for as long as you keep it on the chart.
Moving Average. A moving average weights price over a fixed lookback and forgets the oldest bar every day; an anchored VWAP weights by traded volume from an event and never forgets, so it tracks actual average cost rather than smoothed price.
Pivot Points. Pivots are horizontal formula levels everyone computes identically from the prior session; an anchored VWAP moves with traded volume and depends on the anchor you chose, so it reflects a cohort's cost rather than a shared formula.
Support & Resistance. Horizontal support and resistance mark where price reversed before; an anchored VWAP marks where the money is even when price never reversed there, which is why the two families are strongest in confluence.
Build it in Quant
Type one of these in the Quant desk, or click it. A request that fits a checked template is assembled on the spot without a credit; anything beyond the blanks goes to the copilot, which edits on top of the checked script.
Questions
Why does an anchored VWAP act as support or resistance?
Because it is the average price paid since the anchor. Above the line the cohort is in profit and tends to defend its break-even on pullbacks; below it the same cohort is under water and tends to exit into retests at cost. The line is a position, not a pattern, which is why it can hold even where price never reversed before.
Where should the anchor go?
At an event a real group of traders measures from: a major swing high or low, an earnings or news gap, the breakout bar of a base, an IPO day, or the first bar of a year, quarter or month. If you cannot say which cohort the line represents, the anchor is wrong.
Is anchored VWAP better than a moving average for support and resistance?
It answers a different question. A moving average smooths price over a fixed window; an anchored VWAP measures average cost since an event, weighted by volume. Traders who think in terms of who is trapped and who is in profit prefer the anchored line; both work best in confluence with fixed levels.
Can an anchored VWAP act as resistance after a breakdown?
Yes. Once price accepts below the line, the cohort that went long since the anchor is under water, and its first chance to exit at cost is a retest of the line from beneath. That is the volume-weighted form of role reversal, and a clean reclaim later is an early sign of repair.
Does it work on intraday charts?
Yes, with the same rules. Intraday anchors sit at the session open, the first high-volume bar, or a news candle, and the line matures within hours instead of weeks. On thin intraday volume a young line can bend on one print, so let it age a few bars before trusting a test.
What happens to the level as the anchor gets older?
It slows down. Each bar adds less to sums that already hold months of volume, so the line flattens and stops reacting to single sessions. That is useful: an old, flat anchored VWAP far from price is a deep reference, and a return to it is a larger event than a touch of a young line.