# VWAP strategies on ES futures (5-minute bars, New York session) - specification (RIP Backtest protocol v1.0 plus the 8 Oct 2026 rules)

Specification written and **frozen 2026-10-14 (approved by the owner the same day, draft 1 unchanged)**, before any VWAP, signal or trade of this test was computed. Once frozen, any change of a rule is documented and treated as a separate test; bugs may be fixed.

## Why this test, and what was looked at before
- **Chosen by the owner** on 2026-10-14 from an Investopedia article on common VWAP strategies ("Mastering VWAP: Common Strategies for Informed Trading Decisions", updated 11 Sept 2026). The article describes three uses: (1) trade with the VWAP (long above it, short below), (2) trade against it (long below, short above), and (3) bands of standard deviations around the VWAP, buying in the support region with a stop beyond its outer line and a target at the VWAP, and the mirror for shorts. It states, without a test, that neither of the first two "appears to hold a statistical edge" over many trades. Market and timeframe chosen by the owner the same day: **ES futures, 5-minute bars**, the timeframe people search most for VWAP ("best vwap settings for 5 minute chart"); VWAP needs real volume, which the ES file has.
- Earlier tests on this ES file: many (RSI(2), Supertrend, Bollinger, Donchian, RSI divergence, MACD, golden crosses, Coppock, EMA 9/21, intraday momentum, noise area breakout). The noise area breakout used the session VWAP as part of its trailing stop; no VWAP crossing or VWAP band number was looked at.

## Instrument and data
- **ES** (E-mini S&P 500), 1 contract, NinjaTrader's back-adjusted 1-minute file with real contract volume (`ES_1min.csv`, the loader of the noise area test, `na_lib.load('ES')`), 2020-01-01 to 2026-09-25 17:00 New York, minutes stamped at their close.
- **Session:** 09:30 to 16:00 New York, or the exchange's earlier close on early-close days (calendar of `rb_lib.js`). Only the session's minutes are used; no position is held outside it.
- **5-minute bars** inside the session, closing at 09:35, 09:40, ... up to the session close, built from the minutes that exist (a bar with no minute does not exist).
- **Holes (rule 3):** `data_holes.json`; trades open across a known hole are counted, and every gate and verdict is recomputed without them.

## The session VWAP and its bands
- **Typical price** of a 5-minute bar: (high + low + close) / 3; **VWAP** at the close of bar k: the sum of typical price x volume over the session's bars up to k, divided by their volume (as in the Investopedia formula). It restarts every session.
- **Standard deviation** at bar k: the volume-weighted standard deviation of the typical prices around the VWAP, sqrt(sum(v x tp^2) / sum(v) - VWAP^2), the usual definition of VWAP bands. **Bands:** VWAP +/- 2 and 3 standard deviations.

## The three strategies (long and short)
- **VW-TREND (with the VWAP):** at the close of bar k, a **long signal** when the bar closes above the VWAP after the previous bar closed at or below it; a **short signal** when it closes below after the previous bar closed at or above. A signal opens a position in its direction and closes an opposite one (a flip). Flat at the session close.
- **VW-REV (against the VWAP):** the same crossings with the opposite direction: a close below the VWAP after one at or above it opens a long, a close above after one at or below opens a short. Flips and the session close as above. **It is the exact mirror of VW-TREND**: same entry and exit times, opposite side, so their results before costs are equal and opposite.
- **VW-BANDS (bands, mean reversion):** a **long signal** when a bar closes in the support region, at or below VWAP - 2 SD and at or above VWAP - 3 SD; **stop** one tick ($0.25) below the VWAP - 3 SD line at the signal bar, fixed; **target** the VWAP: the position is closed after the first bar that closes at or above the then current VWAP. Shorts: the mirror (resistance region between + 2 SD and + 3 SD, stop one tick above + 3 SD, out after a close at or below the VWAP). Signals from the bar closing at **10:00** on (the bands need some bars to mean anything; with one bar the deviation is zero). One position at a time; a signal while a position is open is ignored. Flat at the session close.
- **Execution:** entries, flips and exits at the open of the first minute after the signal bar; no signal on the session's last bar. The VW-BANDS stop is checked on every minute from the entry minute on (stop first); a stop gapped through fills at that minute's open.
- **Three variants:** **VW-TREND, VW-REV, VW-BANDS**, all long and short.

## Costs and results
- **Costs:** $30.76 per contract per round trip (commission plus one tick of slippage on each fill), as in every ES test on the site; a flip pays two round trips. Results in **dollars per contract**.

## Periods, gates, control
- **Periods (by entry date):** development 2020 to 2023; validation January 2024 to March 2025; holdout April 2025 to September 2026 (**already used** by earlier ES tests).
- **Six gates per variant:** validation profit factor >= 1.2; at least 50 trades in each period; development **t >= 2.0** (three variants of strategies not tested before on the site); above the 95th percentile of 500 runs of the matched control; positive without the 10 best trades; holdout net positive (flagged used). Fewer than 30 trades: Inconclusive.
- **Matched control (moved entries):** every real trade's entry moved, all together, by one random circular offset of at least 5% of the sessions, to the same time of day in another session, same direction; from there it is managed by the same exit rule of its strategy (the next opposite crossing for VW-TREND and VW-REV, the stop and the VWAP target for VW-BANDS, the session close for all), with the same costs and one position at a time (control trades do not flip). 500 runs, seeds 1000 + run. Statistic: the average net dollars per trade.

## Engine and self-test (before the run)
A new engine (`vw_lib.js`) and a self-test that must pass before any result is printed:
1. Hand-worked sessions: VWAP and its standard deviation; the crossings; flips and their two costs; the mirror relation between VW-TREND and VW-REV; the band entries, the stop (also in the entry minute and gapped), the VWAP target, no entry beyond the 3 SD line, no signal before 10:00 or on the last bar; the session close and an early close.
2. 5-minute session bars and the VWAP against a naive recomputation on the real data.
3. An **independent re-implementation** matched trade by trade for all three variants on the real data.
4. The control at offset 0 reproduces the real trades of all three variants (a flip is booked as two trades, each paying one round trip, so it is the same as a control trade that ends at the minute the next one starts).

## Before the article
Results go to the owner first: all three variants, every gate, long and short separately, trades per day, results before and after costs, by year and by time of day, how trades ended, the hole check. One article, published only with the owner's agreement.

## Reading the result
"Buried" or "Inconclusive" mean a statistically convincing edge was not demonstrated; neither is proof that none exists. One market, one timeframe, the settings described by the article.
