VWAP Pine Script: Anchor, Volume and Band Limits
This example plots a volume-weighted average of chart-bar HLC3 values, resetting when a new daily period begins. It also plots one pair of bands returned by TradingView’s built-in VWAP function. It is a bar-based reference, not an order-execution algorithm, an intrinsic-value estimate or a promise that price will return to the average.
Inspect the Pine ScriptCalculate the weighted average and its reset
For finite source values and nonnegative volumes with positive total volume, VWAP = Σ(source × volume) / Σ(volume), accumulating since the latest anchor. Here source is HLC3 = (high + low + close)/3. This matches the bar-based calculation in TradingView’s VWAP guide.
Take hypothetical source values 100, 110 and 90 with volumes 1, 3 and 2. The first output is 100. After the second bar it is (100 + 330)/4 = 107.5. After the third it is (100 + 330 + 180)/6 = 101.6667. The unweighted three-bar average is 100. A new anchor with source 120 and volume 5 starts a new average at 120, not at zero and not at the previous period’s average.
A bar’s HLC3 is a representative value, not the price of every trade inside it. Aggregating to a different chart interval can change that proxy and the resulting average. Do not claim that this chart calculation exactly reproduces a transaction-level execution benchmark without matching the underlying trades and measurement window.
Distinguish an anchor timeframe from a calculation timeframe
The wrapper accepts a timeframe string, computes anchor = timeframe.change(anchor_timeframe), then passes that Boolean to ta.vwap(source, anchor, stdev_mult). The built-in’s second argument is the reset condition, not the timeframe string itself. The Pine reference states that calculation begins when the anchor first becomes true; prior values are unavailable.
The call below fixes HLC3, a “1D” anchor and multiplier 1. It has no input functions. Editing “1D” to “1W” changes when accumulation restarts; it does not request weekly OHLC or volume. There is no request.security call or second timeframe series in this example.
On a daily chart with a daily reset on each bar, a valid positive-volume bar produces its own source as VWAP; there is no multi-bar accumulation. A weekly anchor on that daily chart can combine several daily sources. For intraday work, inspect the actual reset bars on the selected symbol and session. A new daily period is not automatically a custom 09:30 regular-session anchor, and a universal midnight-UTC rule is not encoded here.
Pine’s timeframe strings express hours in minutes: “60”, “240” and “480” mean one, four and eight hours. “1H” is not a valid Pine timeframe unit, while “1M” means one month. Changing an anchor to an interval shorter than the chart does not reconstruct the missing intrabar observations.
Read the bands as returned values, not probabilities
The three-argument built-in returns VWAP, upper band and lower band. This page delegates the band calculation to that function; it does not replace it with a rolling standard deviation of the plotted cumulative VWAP series. The two green plots and their fill are the one returned pair at multiplier 1. There is no second or third multiplier pair in this copy.
A multiplier of 2 does not establish 95% future price coverage, and a band touch supplies no measured reversal probability or timetable. Treating the output as a normal-distribution confidence interval would require assumptions and evidence that are absent here. Wider bands also do not, by themselves, identify institutional orders or more reliable trades.
To compare another implementation, match source, chart interval, anchor events, volume feed and band definition. Check the center and both bands separately in TradingView’s Data Window. A similar-looking shaded region is insufficient evidence that two calculations agree.
Understand sensitivity without inventing a trading edge
Let W be the prior accumulated volume, A the prior VWAP, x the new source and v the new bar’s volume. Within the same anchor, the updated average is A + v/(W + v) × (x − A), provided the denominator is positive. With A = 100, W = 900, x = 110 and v = 100, the new VWAP is 101. With v = 900 instead, it is 105.
This explains why response depends on both new volume and accumulated volume. It does not imply VWAP always reacts faster than an SMA or EMA. A zero-volume bar contributes no weight to the mathematical average when prior positive volume exists; an entire period with zero total volume has no defined weighted mean. Missing volume is unknown and should not be treated as a genuine zero.
Within an unchanged anchor and for positive v, an increase in VWAP means the new source exceeds the prior average. That identity says nothing about who initiated the trades or the next close. Comparing current close with an HLC3-based average is also different from comparing the chosen source with it. A cross can reflect a reset discontinuity, so decide whether reset-bar signals belong in any later strategy.
Check the market data and timing
Use the exact exchange, session and chart type intended for the calculation. Some TradingView feeds have missing volume or tick-volume counts; these are not interchangeable with traded share or contract quantities. Uniformly scaling all volume weights cancels out, but changing their distribution, provider or coverage can change the average.
The retained code adds no custom missing-data guard, explicit session filter, close-confirmation gate, alert condition or order. HLC3 and accumulated volume can change on the current bar, so the line and bands can move. A daily reset does not mean updates are restricted to daily close.
For a later strategy, define the trigger, reset-bar policy, confirmation time, fill assumptions, exits, sizing and costs. Comparing an execution price with VWAP requires a consistent benchmark interval and side; it does not independently prove a good investment outcome. None of the arithmetic examples establishes a win rate or a profitable entry rule.
Choose the matching VWAP task
This page explains the indicator implementation. For explicit entry and exit definitions, see the VWAP signal strategy guide. For splitting a parent order according to a volume schedule, see the separate VWAP execution algorithm guide.
A rolling VWMA discards older bars as its fixed window advances. Anchored VWAP keeps the period’s earlier observations until its next reset. The distinction is the accumulation window, not a guaranteed ranking of trading performance.
Pine Script v6: implementation and limits
This compact example retains the product helper’s calculation. It plots the built-in center and one band pair from the chart’s data. Review its actual reset events and feed limitations in TradingView before adding execution or alert logic; the visual output alone is not a backtest.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify
//@version=6
indicator(title="Volume Weighted Average Price", overlay=true, max_labels_count=500)
// VWAP calculation — uses HLC3 as source, anchors on daily session (1D), applies 1 standard deviation band
p_ta_vwap(series float source, simple string anchor_timeframe, series float stdev_mult) =>
anchor = timeframe.change(anchor_timeframe)
[vwap, upper, lower] = ta.vwap(source, anchor, stdev_mult)
[vwap, upper, lower]
// Indicator call
[p_ind_1_vwap, p_ind_1_upper, p_ind_1_lower] = p_ta_vwap(hlc3, "1D", 1)
// VWAP Line
plot(p_ind_1_vwap, "VWAP", color.rgb(41, 98, 255, 0), 1)
// Upper and Lower Standard Deviation Bands
p_ind_1_upper_plot = plot(p_ind_1_upper, "VWAP - Upper Band", color.rgb(76, 175, 80, 0), 1)
p_ind_1_lower_plot = plot(p_ind_1_lower, "VWAP - Lower Band", color.rgb(76, 175, 80, 0), 1)
fill(p_ind_1_upper_plot, p_ind_1_lower_plot, color.rgb(76, 175, 80, 95), "VWAP - Background")
Specify a checkable adaptation in Pineify
Ask the Pine Script AI Coding Agent for explicit source, anchor and band-multiplier inputs, plus a displayed reset marker and an agreed missing-volume policy. If the requirement is regular-session-only VWAP, specify the session and timezone rather than assuming a daily anchor supplies them. Check the generated source and chart values against the worked average before relying on alerts. Product access and limits should be checked in Pineify; this guide does not promise instant, unrestricted free generation.
Open Pine Script AI Coding AgentEducational indicator analysis. No measured trading performance is established here. Syntax validation does not prove formula equivalence, execution assumptions or profitability.
Implementation questions
Related Pine Script Tools
What Is VWAP?
Learn the VWAP formula, session reset, chart meaning, and calculation limits with a small worked example.
Best VWAP Settings for Day Trading
Start with a reproducible VWAP baseline, then compare timeframe, source, anchor, and bands one input at a time.
VWAP vs Anchored VWAP
Compare session VWAP and Anchored VWAP by starting point, reset, timeframe, and test use case.
VWAP Reclaim Strategy
Define a closed-bar VWAP reclaim, entry, invalidation, session window, and cost assumptions before testing.
VWAP Order Flow
Combine VWAP price location with Volume Delta or footprint participation data while keeping their limits visible.