Sidechair

ta.vwap()

Browse the reference

Returns the volume-weighted average price of source, restarting whenever anchor is true, with optional standard deviation bands.

Try it in the editor

ta.vwap accumulates source * volume and volume from each anchor bar onward and divides the first total by the second. Everything before the anchor bar is dropped, so the line restarts at that bar's own price.

Pass stdev_mult as a third argument to get a tuple [vwap, upper, lower], where the bands sit stdev_mult volume-weighted standard deviations away from the line. Build the anchor from timeframe.change or any boolean series.

Syntax

Pine Script
ta.vwap(source: series int/float, anchor: series bool) -> series float
ta.vwap(source: series int/float, anchor: series bool, stdev_mult: series int/float) -> [series float, series float, series float]

Arguments

NameTypeDefaultDescription
sourceseries int/floatrequiredPrice series to average, for example hlc3 or close.
anchorseries boolrequiredBoolean series. A true bar starts a new accumulation; false continues the current one.
stdev_multseries int/floatrequiredNumber of volume-weighted standard deviations between the line and each band.

Returns

  • series float: the volume-weighted average price since the latest anchor.
  • [series float, series float, series float]: the VWAP, the upper band and the lower band.

Remarks

  • On Sidechair: when anchor is left out, the accumulation restarts at the start of each trading session of the chart's market.
  • The first bar of a restart returns that bar's source. Bars with zero volume add nothing; a restart on a zero-volume bar yields na.

Example

Pine ScriptDaily-anchored VWAP with bandsOpen in editor
//@version=6
indicator("Anchored VWAP", overlay = true)
newDay = timeframe.change("D")
[vwap, upper, lower] = ta.vwap(hlc3, newDay, 1.0)
plot(vwap, "VWAP", color = color.orange, linewidth = 2)
plot(upper, "Upper", color = color.gray)
plot(lower, "Lower", color = color.gray)

See also

Runs on Sidechair