Skip to content

Free TradingView indicator

Auto-Anchored VWAP

VWAP that restarts automatically at each session, week, month, quarter or year, with an optional deviation band.

Volumev1.0TradingView (Pine Script v6) Non-repainting signals Alerts

What it does

Volume-Weighted Average Price (VWAP) is the average price paid during a period, where each bar counts in proportion to its volume. Many traders read it as a fair-value line: above it, buyers in that period are on average in profit; below it, sellers are.

An anchored VWAP starts its calculation at a chosen moment. This version picks the anchor for you: the start of each session, week, month, quarter or year. It also shows an optional standard deviation band and carries the previous period's final VWAP forward as a reference level.

How it works

  1. At the first bar of each anchor period, the running totals reset.
  2. VWAP = sum of (source × volume) ÷ sum of volume, accumulated bar by bar from the anchor.
  3. Band = VWAP ± multiplier × volume-weighted standard deviation of the source since the anchor.
  4. When a new period starts, the last VWAP of the period that just ended is stored and drawn as "Previous period VWAP". That value is only known after the period closes, so it never changes later.
  5. Close-above and close-below VWAP signals are checked on confirmed bars. A separate alert fires when price crosses the previous period's VWAP.

"Session" uses the symbol's daily boundary in TradingView. For most forex symbols that is the broker or data-feed daily rollover, not a specific trading session such as London.

How to use it

Session VWAP suits intraday charts. Weekly and monthly anchors suit swing traders on H1 to H4 charts who want a slower fair-value line.

Common readings:

  • Price holding above a rising VWAP suggests buyers are in control of that period; below a falling VWAP suggests the opposite.
  • Pullbacks to VWAP in a trending session are often watched as potential entry areas, with confirmation from price action.
  • The previous period's VWAP often acts as support or resistance early in the new period.
  • The band highlights stretched moves away from VWAP.

Settings

InputDefaultWhat it changes
Anchor periodSessionWhen VWAP restarts. Must be longer than the chart timeframe.
Sourcehlc3Price averaged. hlc3 is the usual choice.
Show standard deviation bandonToggles the band.
Band multiplier1.0Band width.
Show previous period's final VWAPonToggles the carried-forward level.
Mark closes across VWAPoffSmall triangles at crosses.

Limitations

  • VWAP needs volume. On spot forex, TradingView volume is usually tick volume from one data provider, which is a proxy for activity rather than true traded volume. Results differ between feeds.
  • Early in a period VWAP moves quickly because few bars are included; it becomes steadier later.
  • The live bar's VWAP changes until the bar closes. Signals wait for the close.
  • The script stops with an error if the anchor is not longer than the chart timeframe (for example a Session anchor on a daily chart) or if the symbol has no volume.
  • VWAP is descriptive. It does not predict direction on its own.

Pine Script source

In TradingView open Pine Editor, paste the code, click Save and then Add to chart.

FXP_AnchoredVWAPAuto.pine

57 lines

// © FXPIPS ONLINE — https://fxpips.online/tradingview-indicators/anchored-vwap-auto/
// License: MIT. Educational tool — not financial advice. Trading involves substantial risk.
//@version=6
indicator("FXP Auto-Anchored VWAP", shorttitle = "FXP AVWAP", overlay = true)

// ── Inputs ─────────────────────────────────────────────────────────────
grpA      = "Anchor"
anchorSel = input.string("Session", "Anchor period", options = ["Session", "Week", "Month", "Quarter", "Year"], group = grpA, tooltip = "VWAP restarts at the first bar of each selected period. 'Session' uses the symbol's daily session boundary.")
src       = input.source(hlc3, "Source", group = grpA)

grpB      = "Band"
showBand  = input.bool(true, "Show standard deviation band", group = grpB)
bandMult  = input.float(1.0, "Band multiplier", minval = 0.1, step = 0.1, group = grpB)

grpVis    = "Display"
showPrev  = input.bool(true, "Show previous period's final VWAP", group = grpVis)
showSig   = input.bool(false, "Mark closes across VWAP", group = grpVis)
vwapCol   = input.color(color.orange, "VWAP color", group = grpVis)
bandCol   = input.color(color.gray, "Band color", group = grpVis)

// ── Calculation ────────────────────────────────────────────────────────
string anchorTf = anchorSel == "Session" ? "D" : anchorSel == "Week" ? "W" : anchorSel == "Month" ? "M" : anchorSel == "Quarter" ? "3M" : "12M"
bool newPeriod  = timeframe.change(anchorTf)

if timeframe.in_seconds() >= timeframe.in_seconds(anchorTf)
    runtime.error("Choose an anchor period longer than the chart timeframe.")

[avwap, bandUp, bandDn] = ta.vwap(src, newPeriod, bandMult)

// Final VWAP value of the period that just ended (known only after it ended, so it never repaints).
var float prevVwap = na
if newPeriod
    prevVwap := avwap[1]

float cumVol = ta.cum(nz(volume))
if barstate.islast and cumVol == 0
    runtime.error("This symbol provides no volume data, so VWAP cannot be calculated.")

bool crossUp = ta.crossover(close, avwap) and barstate.isconfirmed
bool crossDn = ta.crossunder(close, avwap) and barstate.isconfirmed
bool prevX   = ta.cross(close, prevVwap) and barstate.isconfirmed

// ── Plots ──────────────────────────────────────────────────────────────
plot(newPeriod ? na : avwap, "VWAP", color = vwapCol, linewidth = 2, style = plot.style_linebr)
pUp = plot(showBand and not newPeriod ? bandUp : na, "Upper band", color = color.new(bandCol, 30), style = plot.style_linebr)
pDn = plot(showBand and not newPeriod ? bandDn : na, "Lower band", color = color.new(bandCol, 30), style = plot.style_linebr)
fill(pUp, pDn, color = color.new(bandCol, 92), title = "Band fill")
plot(showPrev and not newPeriod ? prevVwap : na, "Previous period VWAP", color = color.new(vwapCol, 40), style = plot.style_linebr)

plotshape(showSig and crossUp, "Close above VWAP", shape.triangleup, location.belowbar, color.teal, size = size.tiny)
plotshape(showSig and crossDn, "Close below VWAP", shape.triangledown, location.abovebar, color.red, size = size.tiny)

// ── Alerts ─────────────────────────────────────────────────────────────
alertcondition(crossUp, "Close above VWAP", "FXP AVWAP: close above the anchored VWAP on {{ticker}} {{interval}} at {{close}}")
alertcondition(crossDn, "Close below VWAP", "FXP AVWAP: close below the anchored VWAP on {{ticker}} {{interval}} at {{close}}")
alertcondition(prevX, "Cross of previous period VWAP", "FXP AVWAP: price crossed the previous period's VWAP on {{ticker}} {{interval}}")

Key inputs

Key inputs of Auto-Anchored VWAP
InputDefaultDescription
Anchor periodSessionPeriod at which the VWAP restarts: Session, Week, Month, Quarter or Year.
Sourcehlc3Price averaged by volume.
Show standard deviation bandtrueDraw a band around VWAP based on the volume-weighted standard deviation.
Band multiplier1.0Band distance in standard deviations.
Show previous period's final VWAPtrueCarry the last VWAP value of the completed period forward as a level.

Educational tools, not advice. Indicators and Expert Advisors describe price; they do not predict it, and past behaviour does not guarantee future results. Test everything on a demo account first and never risk money you cannot afford to lose. See our disclaimer.

Keep exploring

Related tradingview indicators