What is VWAP deviation? Rolling VWAP formula and a backtest

On this page

Key takeaways

  • VWAP, the volume-weighted average price, is the average price at which shares traded over a period: busy days count for more than quiet ones.
  • VWAP deviation says how far the latest close sits above or below that average, in percent. Above zero means the price is higher than where most of the recent volume changed hands.
  • Trading desks use the intraday VWAP, reset each morning, to judge how well a large order was filled. The rolling version on daily bars is a different tool: a volume-weighted moving average.
  • As a trading rule, holding while the price is above its rolling VWAP behaves much like holding while it is above a simple moving average of the same length.
  • Like any short trend rule on daily bars, it switches often and gives part of its return back in whipsaws and trading costs.

Definition

VWAP deviation is the percentage distance between the latest close and a volume-weighted average price (VWAP), an average of recent prices in which each day counts in proportion to the number of shares traded. MarketHeist computes a rolling VWAP over the last 20 daily closes by default, unlike the intraday VWAP that trading desks reset at every market open.

Also known as: VWAP, volume-weighted average price, rolling VWAP, VWAP distance, price vs VWAP, moving VWAP, volume-weighted moving average.

How it works

Multiply each day's close by the number of shares traded that day, add those products up over the window, and divide by the total shares traded. The result is an average price in which a day with three times the usual volume counts three times as much. When every day has the same volume, VWAP is simply the moving average of the closes; the more volume varies, the more VWAP leans toward the prices of the busy days.

The deviation is the close minus VWAP, as a percentage of VWAP. A positive reading says the latest price is above the average price recent buyers paid; a negative one says it is below. Read as sentiment, the first means recent buyers are, on average, sitting on gains and the second on losses, which is why some traders treat VWAP as a level where a falling price finds support or a rising one meets selling.

VWAP began as an execution benchmark. Berkowitz, Logue and Noser proposed in 1988 measuring the cost of a trade against the day's volume-weighted average price, and brokers still sell algorithms that aim to fill an order at or near the day's VWAP. That VWAP starts fresh each morning and uses every trade, or the typical price of each intraday bar. MarketHeist's version is a rolling one: it uses daily closes over a fixed number of past days and never resets, so it is closer to a moving average than to the trading-desk benchmark.

VWAP is like the average price per litre a petrol station's customers paid over the month, counted by how much each one filled up: the days when everyone filled their tank weigh the most.

A rule that holds while the deviation is above zero is a trend rule. It is in the market while the price is above where recent volume traded and out while it is below, with the same strengths and weaknesses as other short moving-average rules: quick to step aside in a sell-off, quick to buy back, and prone to whipsaws when the price hovers around its average.

Formula

Rolling VWAP over W days
VWAPt=∑k=0W−1Ct−kVt−k∑k=0W−1Vt−k
Cₜ
the dividend-adjusted close of day t
Vₜ
shares traded on day t
W
the window: 20 days by default, today included

The intraday VWAP used by trading desks has the same form with every trade, or each intraday bar's typical price (high + low + close) / 3, from the open of the session to now.

Deviation and the rule
Dt=100×Ct−VWAPtVWAPt,st={1Dt>θ0otherwise,rt+1rule=st·rt+1
Dₜ
VWAP deviation in percent
θ
the threshold in percent: 0 by default
sₜ
the position decided at the close of day t: 1 = hold, 0 = cash
rₜ₊₁
the fund's total return on the next day

Worked example

SPY daily bars from Oct 2006 to Sep 2026, about 20 years. Rule: hold SPY for the next day while it closed above its 20-day rolling VWAP, otherwise cash; no trading costs.

SPY closed above its rolling VWAP on 68.8% of days, and the median deviation was 0.96%. After the one-day delay the rule was invested 68.8% of the time and made 294 round trips, 14.7 a year, holding for 11.7 days on average; 34.7% of its trades closed at a gain.

Weighting by volume changed the timing little. The same rule against a plain 20-day average of the closes was invested 66.7% of the time, against 68.8%. Their growth rates, 5.2% and 4.8% a year, show how much a few days' difference in timing can move the result of a short rule.

Holding SPY throughout grew 11.1% a year with a worst decline from a peak of -55.2%; the 20-day rule grew 5.2% with a worst decline of -37.0%. The 200-day version, invested 80.7% of the time, made 3.5 round trips a year instead of 14.7 and grew 7.9% a year with a worst decline of -27.2%.

None of these settings is special. The window, the threshold and the use of volume weights are all choices, and a rule that looks strong on one of them and weak on its neighbours is more likely fitted to this history than describing it; the lab lets you slide the window and see.

Data through Sep 2026. Reproduce id 8c1c05cf39823e4c (this guide, its lab setup and the data month).

Interactive lab

SPY's price with the days the rule held it shaded, VWAP deviation underneath with the zero line, and the results of the 20-day rule, the plain 20-day average, the 200-day rule and buy-and-hold over the same days. Change the window, the threshold, the delay, the cost or the fund.

SPY price with the days the base rule held itS&P 500, adjusted daily close, Oct 2006 to Sep 2026, log scale. Shaded: the 295 stretches the base rule held the fund (69% of 5030 days).$50$100$200$50020062011201620212026SPY adjusted closeHeld by the base rule
SPY on a log scale. Shaded: the days the base rule held the fund. Oct 2006 to Sep 2026.
VWAP deviation % with the base rule's lineVWAP deviation % on SPY, Oct 2006 to Sep 2026. The rule compares it with the fixed line 0.-15-10-50510200620112016202120260VWAP deviation %
VWAP deviation % and the line the base rule compares it with. Oct 2006 to Sep 2026.
Growth of $10,000: the setups against buy and holdS&P 500, Oct 2006 to Sep 2026, log scale. $10,000 grows to $27,379 (base), $25,370 (Price above its 20-day simple average), $45,410 (VWAP deviation, 200-day window), $82,292 (buy and hold).$10k$20k$50k20062011201620212026Base rulePrice above its 20-day simple averageVWAP deviation, 200-day windowBuy and hold
Growth of $10,000 on a log scale, same days for every line. Oct 2006 to Sep 2026.
MeasureBasePrice above its 20-day simple averageVWAP deviation, 200-day windowBuy and hold
CAGR5.2%4.8%7.9%11.1%
Volatility (annualized)11.6%11.3%12.0%19.4%
Maximum drawdown-37.0%-37.1%-27.2%-55.2%
Sharpe ratio0.490.470.690.64
Sortino ratio0.670.640.94n/a
Growth of $10,000$27,379$25,370$45,410$82,292
Time in the market68.8%66.7%80.7%100.0%
Round trips29428569n/a
Round trips per year14.714.33.5n/a
Win rate34.7%35.1%20.3%n/a
Average win3.6%3.5%19.2%n/a
Average loss-1.3%-1.3%-1.7%n/a
Payoff ratio2.752.6911.02n/a
Average days held11.711.757.1n/a
Expectancy per trade0.4%0.4%2.5%n/a
Profit factor, per day1.121.111.141.13
Profit factor, per trade1.471.462.80n/a
Indicator, last day-0.1360.9988.273n/a
Indicator, 10th / 50th / 90th percentile-2.324 / 0.96 / 3.0740.973 / 1.008 / 1.029-4.778 / 6.908 / 13.108n/a
Days the rule alone is long68.8%66.6%80.7%n/a

S&P 500, Oct 2006 to Sep 2026, 5030 trading days. Every setup is measured over the same days, with the indicator warmed up on earlier ones; cash earns 0. Base: Rolling VWAP Deviation (%) (window 20); long while the VWAP deviation % is above 0; execution delay 1; cost 0 bps one way. Price above its 20-day simple average: MA Crossover (short window 1, long window 20, ma type SMA); long while the Short / long average ratio is above 1; execution delay 1; cost 0 bps one way. VWAP deviation, 200-day window: Rolling VWAP Deviation (%) (window 200); long while the VWAP deviation % is above 0; execution delay 1; cost 0 bps one way.

Buy and hold, same daysValue
Largest one-day gain14.5% on 13 Oct 2008
Largest one-day loss-10.9% on 16 Mar 2020
CAGR without the 10 largest gains6.6%
CAGR without the 30 largest gains1.8%
CAGR without the 10 largest losses16.0%
CAGR without the 30 largest losses22.1%

The days replaced by 0 are the largest daily gains (or losses) of the window.

How MarketHeist computes it

Every choice an implementation has to make, as the code makes it today. The page is checked against the code each time it is built.

ChoiceHow it is computedIn the code
DataDaily bars (open, high, low, close, volume) of the fund as the MarketHeist data service serves them to the backtester: prices adjusted for splits and dividends, so a dividend counts as reinvested. They come from a snapshot taken each month and cut at the data month of this page, and are not rounded. The fund's own history, not an extension: a fund younger than the window is measured over the years it has.
WindowThe worked example and the lab measure the last 20 years of trading days, Oct 2006 to Sep 2026 (5030 days), ending at the data month of this page. Every setup, and buy and hold, is measured over exactly these days; an indicator is warmed up on the days before them, so changing a setting never moves the window, and a setting that needs more history than exists before the window is refused rather than measured over fewer days.
BacktestThe backtester's own engine, in the order it runs it: the indicator, the position rule (or entry and exit triggers) and the optional regime filter produce a position for every day of the fund's whole history; the position is then shifted forward by the execution delay and applied to each day's return over the window. Cash earns 0, there is no leverage, and a one-way cost in basis points is charged on the size of every change of position. Round trips are the closed entries of the trade log (a trade still open on the last day is not counted); the win rate is the share of them with a gain; the payoff ratio is the average win over the size of the average loss; expectancy is the average return per trade; the per-trade profit factor is the sum of the winning trades' returns over the size of the sum of the losing ones, while the per-day profit factor sums days.
Years and volatilityA year is 252 trading days, the engine's convention: trades per year is round trips over days divided by 252, the CAGR is the growth multiple to the power 252 over the days, and volatility is the sample standard deviation of the daily returns times the square root of 252.
Indicator statisticsThe indicator's main output over the window: its last value, its 10th, 50th and 90th percentile (linear interpolation between ranks), and the share of days the rule alone says long, before the delay and any regime filter. Every output of the indicator is also summarized by its median and the share of days below 0.
Buy and holdThe fund held every day of the window with dividends reinvested. The largest one-day gain and loss are the highest and lowest daily returns; the CAGR without the 10 or 30 largest gains (or losses) replaces those days' returns with 0 and recompounds.
Rolling VWAPThe sum of close × volume over the last <code>window</code> bars, today included, divided by the sum of volume over the same bars (default 20, from 2 to 500). It uses the daily close, not the typical price (high + low + close) / 3, and never resets; it is not a session VWAP.computepackages/shared/engine/indicators/vwap_dev.ts
Deviation (the signal)(close − VWAP) / VWAP × 100, in percent. No value before the window is full or when the window's volume or VWAP is 0. This is the primary output the position rule reads.SPECpackages/shared/engine/indicators/vwap_dev.ts
Default ruleLong while the deviation is strictly above 0, otherwise flat.generatePositionpackages/shared/engine/positions.ts
Prices and volumeDividend-adjusted closes, so older prices in the window are scaled by the dividends paid since, which moves a 20-day VWAP very little; daily share volume as reported by the data source.yahooResultToRowspackages/platform/ohlcv.ts
Timing, costs and cashThe position decided at a bar's close is applied to the next bar's return (execution delay 1); no trading costs unless set; cash earns 0.runBacktestpackages/shared/engine/backtest.ts
Engine functionsThe functions the portfolio app and the MarketHeist MCP tools run, called here on the same monthly returns.computePositionpackages/shared/engine/run_basic.tsgeneratePositionpackages/shared/engine/positions.tsapplyRegimeFilterpackages/shared/engine/regime_filter.tsgenerateTriggeredPositionpackages/shared/engine/triggered_position.tsrunBacktestpackages/shared/engine/backtest.tsgetIndicatorpackages/shared/engine/indicators/registry.ts

VWAP deviation (rolling VWAP) compared with its neighbours

Rolling VWAP and its neighbours
AverageWeightsResetsTypical use
Intraday VWAPEach trade's sizeEvery sessionExecution benchmark for large orders
Anchored VWAPEach bar's volumeFrom a chosen event, such as an earnings dateSupport and resistance from that event
Rolling VWAP (MarketHeist)Each day's volumeNever: a moving window of daily closesTrend rule: price above or below it
Simple moving averageEqualNeverTrend rule
Exponential moving averageNewest days mostNeverTrend rule that reacts faster

Limitations

  • This is not the VWAP on a trading screen. It uses daily closes over a moving window, so its values differ from a session VWAP or an anchored VWAP on the same fund.
  • Volume weights can be dominated by mechanical heavy days, such as index rebalancing or option expiries, that say nothing about where investors were willing to buy.
  • Short windows whipsaw: the price crosses its 20-day average many times a year, and each round trip costs trading fees that the zero-cost test leaves out.
  • The window and threshold are choices; results change with both, and with the fund and the period.
  • The test ignores spreads and taxes, earns nothing on cash, trades at the close of the signal day and describes one historical path of one fund.

Frequently asked questions

Is this the same VWAP as on my trading platform?
Usually not. Platforms show a session VWAP that starts at each open and weights every trade, or each intraday bar's typical price. MarketHeist's rolling VWAP uses the daily close and volume over a moving number of past days, which makes it a volume-weighted moving average.
Why weight prices by volume?
Because a price at which many shares changed hands says more about what investors were willing to pay than a price set on a thin day. The volume-weighted average stays close to where most of the money actually traded.
What does a negative VWAP deviation mean?
That the latest close is below the volume-weighted average of recent prices: on average, recent buyers are sitting on a loss. Trend rules read it as weakness; mean-reversion rules sometimes read a deep negative reading as a chance to buy.
What is anchored VWAP?
A VWAP that starts from a chosen date, such as a major low or an earnings release, and keeps accumulating from there, so it shows the average price paid by everyone who bought since that event. MarketHeist's indicator is rolling, not anchored.

References

  1. Berkowitz, S. A., Logue, D. E. and Noser, E. A. (1988) The Total Cost of Transactions on the NYSE. Journal of Finance 43(1). The volume-weighted average price as a benchmark for trading costs.
  2. Brock, W., Lakonishok, J. and LeBaron, B. (1992) Simple Technical Trading Rules and the Stochastic Properties of Stock Returns. Journal of Finance 47(5). Moving-average rules on daily data.
  3. Blume, L., Easley, D. and O'Hara, M. (1994) Market Statistics and Technical Analysis: The Role of Volume. Journal of Finance 49(1).

Try it on your own holdings

Run the VWAP-deviation rule on SPY in the backtester →

Or ask an assistant connected to the MarketHeist MCP server (https://marketheist.io/mcp), which computes the same figures:

Using MarketHeist.io, backtest SPY on daily bars with the rolling VWAP deviation (20-day window): hold SPY while the close is above its rolling VWAP, otherwise cash, one-bar delay, no costs, over the last 20 years. Compare it with the same rule on a plain 20-day moving average and with buy-and-hold.

Ask an AI assistant

The prompt opens in a new tab, already filled in. An assistant without the MarketHeist connector answers from its own knowledge, not from the figures on this page.

Historical simulation, not advice. Computed by the MarketHeist portfolio engine from monthly total returns, data through Sep 2026. Markdown version of this page: vwap-deviation.md.