# What is VWAP deviation? Rolling VWAP formula and a backtest

Canonical URL: https://marketheist.io/portfolio/learn/vwap-deviation
By Jeffrey Lin · Published 2026-11-25 · Updated 2026-11-25 · Data through Sep 2026
Category: Indicators

## 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**

```
VWAP_t = \frac{\sum_{k = 0}^{W - 1} C_{t - k} V_{t - k}}{\sum_{k = 0}^{W - 1} V_{t - k}}
```

where:

- 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**

```
D_t = 100 \times \frac{C_t - VWAP_t}{VWAP_t}, s_t = {\begin{pmatrix} 1 & D_t > \theta \\ 0 & otherwise \end{pmatrix}, r_{t + 1}^{rule} = s_t \cdot r_{t + 1}
```

where:

- 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).

## How MarketHeist computes it

- **Data**: Daily 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.
- **Window**: The 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.
- **Backtest**: The 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 volatility**: A 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 statistics**: The 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 hold**: The 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 VWAP**: The sum of close × volume over the last window 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. (`compute` in packages/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. (`SPEC` in packages/shared/engine/indicators/vwap_dev.ts)
- **Default rule**: Long while the deviation is strictly above 0, otherwise flat. (`generatePosition` in packages/shared/engine/positions.ts)
- **Prices and volume**: Dividend-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. (`yahooResultToRows` in packages/platform/ohlcv.ts)
- **Timing, costs and cash**: The 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. (`runBacktest` in packages/shared/engine/backtest.ts)
- **Engine functions**: `computePosition` (packages/shared/engine/run_basic.ts), `generatePosition` (packages/shared/engine/positions.ts), `applyRegimeFilter` (packages/shared/engine/regime_filter.ts), `generateTriggeredPosition` (packages/shared/engine/triggered_position.ts), `runBacktest` (packages/shared/engine/backtest.ts), `getIndicator` (packages/shared/engine/indicators/registry.ts)

## VWAP deviation (rolling VWAP) compared with its neighbours

Rolling VWAP and its neighbours

| Average | Weights | Resets | Typical use |
| --- | --- | --- | --- |
| Intraday VWAP | Each trade's size | Every session | Execution benchmark for large orders |
| Anchored VWAP | Each bar's volume | From a chosen event, such as an earnings date | Support and resistance from that event |
| Rolling VWAP (MarketHeist) | Each day's volume | Never: a moving window of daily closes | Trend rule: price above or below it |
| Simple moving average | Equal | Never | Trend rule |
| Exponential moving average | Newest days most | Never | Trend 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

App: https://marketheist.io/backtest/?c=eyJ0aWNrZXIiOiJTUFkiLCJmcmVxdWVuY3kiOiIxZCIsImluZGljYXRvcl9pZCI6InZ3YXBfZGV2IiwiaW5kaWNhdG9yX3BhcmFtcyI6eyJ3aW5kb3ciOjIwfSwicG9zaXRpb25fcnVsZSI6eyJ0eXBlIjoidGhyZXNob2xkIiwidGhyZXNob2xkIjowLCJkaXJlY3Rpb24iOiJhYm92ZSJ9LCJleGVjdXRpb25fZGVsYXkiOjEsInRyYW5zYWN0aW9uX2Nvc3RzX2JwcyI6MCwibGV2ZXJhZ2UiOnsibW9kZSI6Im5vbmUifX0

MCP prompt (MarketHeist MCP server, https://marketheist.io/mcp):

```
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.
```

Historical simulation, not advice.
