VWAP in Pine Script
The session's volume-weighted average price, reset at every open: the day's running fair value and the break-even of everyone who has traded since the open.
Definition
VWAP, the volume-weighted average price, is the average price at which a market has traded during the current session, with every bar counted in proportion to its volume. It belongs to the VWAP and cost-basis family alongside the anchored VWAP. The calculation starts on the first bar of the session, runs to the last and then resets, so on any bar the line shows the average price paid by everyone who has traded that day. Heavy bars pull the line towards their price; quiet bars barely move it.
The line matters because it is a cost basis, not a smoothed price. While price sits above a rising VWAP the average intraday buyer is in profit, and pullbacks into the line tend to find demand. Below a falling VWAP the average buyer is under water, and rallies into the line tend to meet supply. Institutional desks are also measured against it: a fill better than VWAP is a good fill, so large orders are sliced through the day to track it, which adds real order flow around the line.
VWAP began as an execution benchmark on institutional desks in the late 1980s and reached retail charts once intraday volume data became common. The standard setting has no length at all. The only choices are the source, usually the typical price, and the deviation multiplier for the bands, which sit 1 and 2 volume-weighted standard deviations from the line. The bands show how far price has stretched from the day's average business, and most platforms draw both by default.
Expect the line to be jumpy for the first few bars, when a handful of prints decide it, and to steady as the session's volume accumulates. By the afternoon it moves slowly and a fast market can leave it far behind. On a range day price crosses the line repeatedly and the bands contain most of the action. On a trend day price holds one side, the outer band stretches and the line trails price like a slow moving average. The reset at the next open wipes the slate; yesterday's VWAP has no bearing on today's line.
Reading the chart
Reading VWAP starts with the clock, because the line's meaning changes as the session ages.
- Confirm the chart is intraday and the session boundary matches the market you trade. The line resets on the daily bar of the data feed, so the first bar of that day is the anchor.
- Ignore the first few bars after the open. With little volume in the sums one large print can swing the line, and early crosses are noise more often than signal.
- Note which side of the line price is holding and whether the line is rising, flat or falling. Above a rising line is a buyer's session; below a falling line is a seller's.
- Watch the pullbacks into the line. A defended test, where price touches and closes back on its side, confirms the bias; a close through it and a failed retest from the other side flips it.
- Use the bands as a stretch gauge. Price at the second band is far from the day's average cost, which favours fading in a range and trailing rather than adding in a trend.
- Mark the confluence with fixed levels. Where the moving line meets the previous day's close, a pivot or the opening range extreme, the overlap is a stronger zone than either alone.
The maths
VWAP at any bar is the session's sum of price times volume divided by the session's sum of volume, and the bands use the volume-weighted spread of prices around it.
The sums restart on the first bar of each new day as the chart's daily bar defines it. On a 24-hour market that boundary is the data feed's day change, not a floor bell, so check where the line resets.
The implementation uses the typical price by default; the source input can be switched to the close. The second band is always twice the first, so a multiplier of 1 draws bands at 1 and 2 deviations.
On daily and higher timeframes the session holds a single bar and the line collapses to that bar's typical price, so the script hides its signals there and the tool is intraday only.
The deviation is volume-weighted and computed from the same running sums, so the bands widen as the day's trading spreads across more prices, not simply as the bars get taller.
Inputs that matter
| Input | Typical | What changing it does |
|---|---|---|
| Band deviation | 1 (the outer band at 2) | Widening the multiplier pushes the bands to rarer extremes, so touches become fewer and more meaningful. Narrower bands flag stretch earlier but far more often. |
| Source | typical price (hlc3) | A close-based line sits a little differently on wide-range bars; on liquid names the difference is small. |
| Session | the daily bar of the data feed | For stocks a regular-hours session and an extended-hours session give different lines; read the one that matches the volume you trade against. |
In practice
- As a bias line: above a rising VWAP the rule looks for longs on pullbacks to it, and rallies into a falling VWAP from below are short entries. The side of the line is the day's default direction.
- As dynamic support and resistance: the first clean test of the line after the open is the most watched, when the line has enough volume to be stable and the day's cohort still defends its cost.
- As a mean-reversion frame on range days: the rule fades touches of the second band back towards the line when the line is flat, and stands aside if price closes beyond the band and holds there.
- As a trend-day filter: when price has not returned to the line by mid-session, fading stops; trailing rules use the first band instead and let the distance from the line manage the position.
- As an execution benchmark: a long filled below VWAP or a short filled above it was better than the day's average trade, the same yardstick institutional desks are measured against.
- As confluence with fixed levels: a VWAP test that lines up with the previous close, a pivot or the opening range high carries more weight than a test in empty space.
Where it goes wrong
- Reading the line on a daily chart. With one bar per session it is just that bar's typical price; use it on intraday bars and use an anchored VWAP for a multi-day cost basis.
- Trusting the first few bars. A single large print can move a young line by several ticks; wait until the session has volume behind it before reading a test.
- Fading the second band on a trend day. Stretch is normal when price is trending away from the line; check that the line is flat and price has been crossing it before fading.
- Setting alerts at a fixed price. The line moves every bar, so an alert on a number goes stale within minutes; alert on the cross of the live line instead.
Compared with
Anchored VWAP. Session VWAP restarts at every open, so it measures the cost basis of today's traders only; an anchored VWAP is pinned to a chosen event and carries that cohort's average cost across days and weeks. Use the session line for intraday bias and the anchored line for swing context.
Moving Average. A moving average smooths price over a fixed number of bars and treats a quiet bar and a heavy bar alike; VWAP weights every bar by its volume and has no lookback, only a start point. The average follows price, VWAP follows money.
Bollinger Bands. Bollinger Bands sit a set number of standard deviations around a moving average and measure recent price volatility over a lookback; VWAP bands sit around the session's average cost and measure how widely the day's trading has spread, weighted by volume.
Pivot Points. Pivots are fixed horizontal levels computed once from yesterday's range and shared by everyone; VWAP moves with every print and depends on the session's own volume, so the two are strongest where the moving line crosses a fixed one.
Build it in Quant
Type one of these in the Quant desk, or click it. A request that fits a checked template is assembled on the spot without a credit; anything beyond the blanks goes to the copilot, which edits on top of the checked script.
Questions
Why does VWAP reset every day?
Because it is a session benchmark. The line answers one question: what is the average price paid today, weighted by volume. Carrying yesterday's volume forward would blend two auctions and blur the answer. When you want a cost basis that spans days, anchor the calculation to an event instead of the open.
Which timeframe should I use VWAP on?
Any intraday timeframe, because the line is nearly the same on all of them: the calculation runs over the bars of the session, and a 1-minute chart and a 15-minute chart of the same day give almost identical lines. On daily bars the session contains one bar and the line is meaningless.
Is VWAP support or resistance?
Both, depending on which side price is on. Above the line the average buyer of the day is in profit and tends to add on pullbacks, so the line acts as support. Below it the same buyers are under water and reduce into rallies, so the line acts as resistance. A close through the line changes its role.
What do the deviation bands mean?
They measure how far price has moved from the day's average cost, in units of the volume-weighted spread of prices. The first band holds the bulk of a normal session's trading; the second is a stretch. On a range day the bands are where fades happen; on a trend day price rides one of them.
Does VWAP work on crypto and futures?
Yes, with one check. Both trade around the clock, so the session boundary is whatever the data feed calls a new day, and the line resets there rather than at a floor open. Many futures traders prefer a line reset at the regular-hours open, which needs a session input or an anchor at that bar.
How is VWAP different from a moving average of price?
A 20-bar average gives every bar the same weight and forgets the oldest bar each step. VWAP gives each bar a weight proportional to its volume and forgets nothing until the reset. Two bars at the same price but different volume move VWAP by different amounts and move a moving average identically.