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
- At the first bar of each anchor period, the running totals reset.
- VWAP = sum of (source × volume) ÷ sum of volume, accumulated bar by bar from the anchor.
- Band = VWAP ± multiplier × volume-weighted standard deviation of the source since the anchor.
- 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.
- 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
| Input | Default | What it changes |
|---|---|---|
| Anchor period | Session | When VWAP restarts. Must be longer than the chart timeframe. |
| Source | hlc3 | Price averaged. hlc3 is the usual choice. |
| Show standard deviation band | on | Toggles the band. |
| Band multiplier | 1.0 | Band width. |
| Show previous period's final VWAP | on | Toggles the carried-forward level. |
| Mark closes across VWAP | off | Small 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}}")

