Skip to content
GetProfitable
Search
Volume

VWAP with Standard Deviation Bands

Session anchored VWAP with bands at one and two standard deviations, which turns the day's volume weighted average price into a measure of how far the session has stretched away from it.

indicator
//@version=6
indicator("VWAP with Standard Deviation Bands", "VWAP SD", overlay = true)

src = input.source(hlc3, "Source", group = "Settings")
devInner = input.float(1.0, "Inner deviations", minval = 0.1, step = 0.1, group = "Settings")
devOuter = input.float(2.0, "Outer deviations", minval = 0.1, step = 0.1, group = "Settings")
showOuter = input.bool(true, "Show outer band", group = "Settings")
lineCol = input.color(#2962FF, "VWAP", group = "Style")
bandCol = input.color(#787B86, "Bands", group = "Style")
bull = input.color(#26A69A, "Crossed up", group = "Style")
bear = input.color(#EF5350, "Crossed down", group = "Style")

newSession = timeframe.change("D")

[vwapLine, innerUp, innerDown] = ta.vwap(src, newSession, devInner)

spread = devOuter / devInner
outerUp = vwapLine + (innerUp - vwapLine) * spread
outerDown = vwapLine - (vwapLine - innerDown) * spread

plot(vwapLine, "VWAP", color = lineCol, linewidth = 2)
pInnerUp = plot(innerUp, "Inner upper", color = color.new(bandCol, 30))
pInnerDown = plot(innerDown, "Inner lower", color = color.new(bandCol, 30))
fill(pInnerUp, pInnerDown, color = color.new(lineCol, 94), title = "Inner band")
plot(showOuter ? outerUp : na, "Outer upper", color = color.new(bandCol, 55))
plot(showOuter ? outerDown : na, "Outer lower", color = color.new(bandCol, 55))

crossedUp = ta.crossover(close, vwapLine)
crossedDown = ta.crossunder(close, vwapLine)
plotshape(crossedUp, "Above VWAP", location = location.belowbar, style = shape.triangleup, color = bull, size = size.tiny)
plotshape(crossedDown, "Below VWAP", location = location.abovebar, style = shape.triangledown, color = bear, size = size.tiny)
alertcondition(crossedUp, "Crossed above VWAP", "Price crossed above the session VWAP")
alertcondition(crossedDown, "Crossed below VWAP", "Price crossed below the session VWAP")
This runs in TradingView, not here
Pine Script only executes inside TradingView. Paste the source into the Pine Editor and add it to a chart to see it plotted.

What it will not do

  • VWAP resets at every session open, so the first bars of a day are computed from almost no volume and the bands swing wildly there.
  • By the close the average is anchored to hours of old volume and barely moves, which is not the same as price agreeing with it.
  • The bands describe how widely the session has traded around its average. They are dispersion, not support and resistance.
  • TradingView reports tick count rather than traded size for spot forex, so a volume weighted average means much less on those symbols.

Written from this description

Plot the session anchored VWAP with bands at one and two standard deviations, shade the inner band, and mark the bars where price crosses the VWAP itself.

Educational only, not financial advice. The maths is simple arithmetic on the numbers you enter; it knows nothing about your broker, fees, slippage or the market. Something wrong with it? Say so in Site Feedback.