Edgoro
Volume indicator

Anchored VWAP: where to anchor it, bands and Pine Script v6 code

How anchored VWAP measures the average price paid since an event you choose, where traders anchor it, how to read it, and a free anchored VWAP script.

What it measures

Anchored VWAP is the volume-weighted average price calculated from a bar you choose, instead of from the start of each session. It answers a specific question: on average, what price have buyers and sellers paid since that event? If price is above the anchored VWAP, the volume traded since the anchor was, on average, bought below the current price.

The calculation is the same as the regular VWAP; only the starting point changes, and it never resets. Brian Shannon is closely associated with popularising the anchored approach.

The formula in words

  1. Pick the anchor: the first bar that opens at or after the date and time you choose.
  2. From that bar on, for every bar, take the typical price, (high + low + close) ÷ 3, and multiply it by the bar's volume.
  3. Keep running totals of price × volume and of volume.
  4. Anchored VWAP = total price × volume ÷ total volume.
  5. For bands, compute the volume-weighted standard deviation of price around the VWAP and add or subtract a multiple of it.

Because it accumulates from a fixed point, an anchored VWAP gets steadier the further you are from the anchor: each new bar is a smaller share of the total volume.

How traders read it

  • Where to anchor. Common anchors are events that changed the market's mind: an earnings release, a major swing high or low, a gap, the start of a year or quarter, or a breakout bar.
  • Support and resistance. A VWAP anchored at a swing low is watched as support during an uptrend: a return to it means the average buyer since the low is back at break-even.
  • Who is in profit. Price above a VWAP anchored at a swing high means buyers since that high are, on average, in profit; below it, they're on average at a loss.
  • Several anchors. Traders often keep two or three anchors (the last major high, the last major low, the start of the year) and watch where they cluster.

Common settings

SettingTypical valueNotes
AnchorA swing, gap, news bar or calendar dateThe choice is the whole point.
Sourcehlc3The typical price.
Bands1 and 2 standard deviationsOptional.
TimeframeAny chart with volumeWorks on daily charts too, unlike a session VWAP.

Pine Script v6 code

The complete, self-contained script is below. Copy it into a new indicator in TradingView's Pine Editor, or download the .pine file.

Pine Script v6
//@version=6
indicator("Anchored VWAP from a chosen bar", shorttitle = "AVWAP", overlay = true)

anchorTime = input.time(timestamp("02 Jan 2026 00:00 +0000"), "Anchor date and time", confirm = true, group = "Anchor")
src        = input.source(hlc3, "Source", group = "Calculation")
showBands  = input.bool(true, "Show deviation bands", group = "Bands")
mult1      = input.float(1.0, "Band 1 (x stdev)", minval = 0.1, step = 0.1, group = "Bands")
mult2      = input.float(2.0, "Band 2 (x stdev)", minval = 0.1, step = 0.1, group = "Bands")

// The calculation starts on the first bar that opens at or after the anchor time and never resets.
started  = time >= anchorTime
isAnchor = started and not started[1]

vol = nz(volume)
var float sumPV  = 0.0
var float sumV   = 0.0
var float sumPV2 = 0.0

if started
    sumPV  += src * vol
    sumV   += vol
    sumPV2 += src * src * vol

avwap = started and sumV > 0 ? sumPV / sumV : na
sd    = started and sumV > 0 ? math.sqrt(math.max(sumPV2 / sumV - avwap * avwap, 0)) : na

plot(avwap, "Anchored VWAP", color = color.new(color.orange, 0), linewidth = 2)
u1 = plot(showBands ? avwap + mult1 * sd : na, "Upper 1", color = color.new(color.gray, 30))
l1 = plot(showBands ? avwap - mult1 * sd : na, "Lower 1", color = color.new(color.gray, 30))
plot(showBands ? avwap + mult2 * sd : na, "Upper 2", color = color.new(color.gray, 60))
plot(showBands ? avwap - mult2 * sd : na, "Lower 2", color = color.new(color.gray, 60))
fill(u1, l1, color = color.new(color.orange, 92), title = "Band 1 fill")
plotshape(isAnchor, "Anchor bar", shape.diamond, location.belowbar, color.new(color.orange, 0), size = size.tiny)

crossAbove = ta.crossover(close, avwap)
crossBelow = ta.crossunder(close, avwap)
alertcondition(crossAbove, "Close above anchored VWAP", "{{ticker}} closed above the anchored VWAP ({{interval}})")
alertcondition(crossBelow, "Close below anchored VWAP", "{{ticker}} closed below the anchored VWAP ({{interval}})")

totalVol = ta.cum(vol)
if barstate.islast and totalVol == 0
    runtime.error("This symbol has no volume data, so VWAP can't be calculated.")

When you add the script to a chart, TradingView asks you to click the anchor bar (input.time() with confirm = true); you can change the date later in the settings. A diamond marks the anchor bar, and the VWAP and two optional pairs of deviation bands are drawn from there on.

Alert conditions fire when price closes above or below the anchored VWAP. The script stops with an error message on symbols with no volume data.

Add it to your chart

  1. Open any chart on TradingView and open the Pine Editor.
  2. Create a new indicator, delete the template code and paste the script.
  3. Click Save, then Add to chart. Change lengths and levels from the indicator's settings.

Stuck on an error? See how to add a Pine Script indicator to TradingView.

Pitfalls

  • Anchoring in hindsight. It's easy to pick the anchor that "worked" on a past chart. Decide the type of anchor (for example, every earnings bar) before you look.
  • The anchor bar on higher timeframes. If the anchor time falls inside a bar, the calculation starts on the next bar that opens at or after it. On weekly bars that can move the start by days.
  • Tick volume. On spot forex and many CFDs, volume is a count of price changes, so the average is weighted by activity, not traded size.
  • Too many anchors. With enough lines on the chart, price is always near one of them.

The script is an educational example: test it on your own markets before relying on it. Indicators describe the past; they don't predict the future. Trading involves substantial risk of loss and is not suitable for every investor. Edgoro is a software tool, not a broker or financial adviser: nothing it produces is investment advice, and past or backtested performance does not guarantee future results.

Make it yours with Edgoro

Describe the change in plain English and Edgoro writes the Pine Script v6 for you, ready to paste. For example:

“Plot an anchored VWAP from the last earnings bar with 1 and 2 standard deviation bands, and alert when price closes back above it, once per bar close.”

Build your Anchored VWAP indicator