VWAP reversion strategy
On ES futures, the VWAP reversion strategy lost $99,597 after costs and ran a $100,000 account down to its margin on April 9, 2025. The run stops there.
Mean reversionIntraday1-minute barsBacktested Nov 6, 2026
VWAP reversion backtest, the result
Contract
E-mini S&P 500
-
−$99.6K
Net after costs
After $78,660 in fees and slippage
-
2 of 10
Years that made money
January 2016 to April 2025
-
−$104K
Largest drawdown
Peak to trough, 1 contract
-
−$36
Average trade
2,758 trades
Net after costs by month, January 2016 to April 2025.
VWAP reversion rules
Trade back to the session's VWAP when price has stretched 2 standard deviations away from it.
A drawing of the rules on a made-up day, not a result.
- The VWAP is the Globex session's, from its 18:00 New York open, over each one-minute bar's typical price (high + low + close) / 3, with the volume-weighted standard deviation of that price around it.
- In the day session, a one-minute close above VWAP + 2 deviations sells short and one below VWAP - 2 deviations buys.
- The position is closed when a one-second close reaches the VWAP, or at 15:45 New York.
- A new entry may follow an exit the same day.
- Decides on
- 1-minute bars
- Holds
- Nothing overnight
- Parameters
- bands 2, open minute 570, exit minute 945, session minute 1,080
Results by year
It made money in 2 of 10 years on ES. Its best year was 2019, +$6,197, and its worst 2022, −$25,812. The account was closed out on April 9, 2025, so the years stop there.
| Year | Net | Trades | Win rate | Drawdown | Buy and hold |
|---|---|---|---|---|---|
| 2016 | −$3,627 | 287 | 62% | −$4,529 | +$11,497 |
| 2017 | −$4,750 | 311 | 61% | −$6,741 | +$21,936 |
| 2018 | −$16,218 | 333 | 63% | −$18,066 | −$8,589 |
| 2019 | +$6,197 | 273 | 65% | −$5,161 | +$35,436 |
| 2020 | +$4,638 | 223 | 55% | −$19,360 | +$27,761 |
| 2021 | −$14,127 | 272 | 57% | −$19,724 | +$51,361 |
| 2022 | −$25,812 | 314 | 62% | −$34,649 | −$45,939 |
| 2023 | −$5,426 | 330 | 65% | −$17,801 | +$38,435 |
| 2024 | −$15,149 | 327 | 65% | −$21,130 | +$42,947 |
| 2025, Jan to Apr | −$25,322 | 88 | 64% | −$29,706 | +$37,010 |
VWAP reversion backtest results
On ES it lost $20,938 before costs, then paid $78,660 in fees and slippage.
- Net = before costs − fees − slippage
- ES: −$20,938 − $9,710 − $68,950 = −$99,597
The whole interval is under zero: after costs, the average trade lost money.
VWAP reversion code and Pine Script
The strategy as the backtest ran it, and the Pine Script our compiler wrote from it for TradingView.
1import math2 3from atlantive import BUY, NEW_YORK, SELL, Bars, Session, Strategy4 5 6class VwapReversion(Strategy):7 """Fade a one-minute close two standard deviations from the session VWAP, New York day session.8 9 The VWAP is the Globex session's, from its 18:00 New York open: the volume-weighted mean of each10 one-minute bar's typical price (high + low + close) / 3, with the volume-weighted standard11 deviation of that price around it. In the day session, a one-minute close above VWAP + 212 deviations sells short and one below VWAP - 2 deviations buys. The position is closed when a13 one-second close reaches the VWAP (as of the last finished minute), or at 15:45. A new entry14 may follow an exit the same day. The clock is one-second bars; the minutes are built from them.15 """16 17 data = "bars"18 19 class Params:20 bands: float = 2.021 open_minute: int = 57022 exit_minute: int = 94523 session_minute: int = 108024 clip: int = 125 26 class State:27 clock: Session(zone=NEW_YORK)28 bars: Bars(interval_ns=1_000_000_000)29 session_key: int30 origin: float31 sum_v: float32 sum_pv: float33 sum_ppv: float34 vwap: float35 dev: float36 ready: bool37 bar_key: int38 bar_high: float39 bar_low: float40 bar_close: float41 bar_volume: float42 bar_minute: int43 bar_session: int44 45 def on_event(self, view, ev, orders):46 self.clock.update(ev)47 if not self.bars.update(ev):48 return49 minute = self.clock.prev_minute50 second = self.clock.prev_second51 day = self.clock.prev_day52 high = float(self.bars.prev_high)53 low = float(self.bars.prev_low)54 close = float(self.bars.prev_close)55 volume = float(self.bars.prev_volume)56 key = day * 1440 + minute57 session = day58 if minute >= self.p.session_minute:59 session = day + 160 if key != self.bar_key:61 if self.bar_key != 0:62 # The minute bar_key closed: fold it into its session's VWAP, then judge its close.63 if self.bar_session != self.session_key:64 self.session_key = self.bar_session65 self.origin = self.bar_close66 self.sum_v = 0.067 self.sum_pv = 0.068 self.sum_ppv = 0.069 self.ready = False70 typical = (self.bar_high + self.bar_low + self.bar_close) / 3.0 - self.origin71 self.sum_v += self.bar_volume72 self.sum_pv += self.bar_volume * typical73 self.sum_ppv += self.bar_volume * typical * typical74 if self.sum_v > 0:75 mean = self.sum_pv / self.sum_v76 var = self.sum_ppv / self.sum_v - mean * mean77 self.vwap = self.origin + mean78 self.dev = 0.079 if var > 0:80 self.dev = math.sqrt(var)81 self.ready = True82 in_session = self.bar_minute >= self.p.open_minute and self.bar_minute + 1 < self.p.exit_minute83 if self.ready and in_session and view.position == 0 and self.dev > 0:84 if self.bar_close > self.vwap + self.p.bands * self.dev:85 orders.ioc(side=SELL, qty=self.p.clip)86 elif self.bar_close < self.vwap - self.p.bands * self.dev:87 orders.ioc(side=BUY, qty=self.p.clip)88 self.bar_key = key89 self.bar_minute = minute90 self.bar_session = session91 self.bar_high = high92 self.bar_low = low93 self.bar_volume = volume94 else:95 self.bar_high = max(self.bar_high, high)96 self.bar_low = min(self.bar_low, low)97 self.bar_volume += volume98 self.bar_close = close99 # Exits on every one-second close.100 late = second + 1 >= self.p.exit_minute * 60 or minute < self.p.open_minute101 if view.position < 0:102 if close <= self.vwap or late:103 orders.ioc(side=BUY, qty=self.p.clip)104 elif view.position > 0:105 if close >= self.vwap or late:106 orders.ioc(side=SELL, qty=self.p.clip) 1//@version=62// VwapReversion, exported from Atlantive.3// Chart simulation: decisions use completed bars; market orders fill at the next bar open.4// Native fills, fees, data gaps and session boundaries can differ. Re-test on the target symbol.5// Use standard time-based candles and the strategy's timeframe, not synthetic chart prices.6// Pine v6 trims old trade records at its order limit; the strategy keeps calculating.7// Margin is explicitly disabled to retain the native signal simulation's sizing.8strategy("VwapReversion", overlay=true, initial_capital=100000.0, commission_type=strategy.commission.cash_per_contract, commission_value=1.68, default_qty_type=strategy.fixed, default_qty_value=1, calc_on_every_tick=false, process_orders_on_close=false, slippage=0, margin_long=0, margin_short=0)9 10if timeframe.in_seconds() != 111 runtime.error("VwapReversion was exported for the 1 second timeframe; set the chart to 1S.")12 13bands = input.float(2.0, "bands")14open_minute = input.int(570, "open_minute", minval=-9007199254740991, maxval=9007199254740991)15exit_minute = input.int(945, "exit_minute", minval=-9007199254740991, maxval=9007199254740991)16session_minute = input.int(1080, "session_minute", minval=-9007199254740991, maxval=9007199254740991)17clip = input.int(1, "clip", minval=-9007199254740991, maxval=9007199254740991)18 19_q_safe_int(x) =>20 if math.abs(x) > 900719925474099121 runtime.error("an integer left the exact chart range; this run cannot be compared faithfully")22 int(x)23_q_int(x) => _q_safe_int(x < 0 ? math.ceil(x) : math.floor(x))24_q_iadd(a, b) => _q_safe_int(a + b)25_q_imul(a, b) =>26 if a != 0 and math.abs(b) > 9007199254740991 / math.abs(a)27 runtime.error("an integer multiplication left the exact chart range; this run cannot be compared faithfully")28 _q_safe_int(a * b)29 30_q_high = _q_int(math.round(high * 1000000000.0))31_q_low = _q_int(math.round(low * 1000000000.0))32_q_close = _q_int(math.round(close * 1000000000.0))33// Set to the native instrument quantity step; futures contracts usually use 1.34_q_volume_unit = input.float(1.0, "Volume units per quantity step", minval=0.000000001)35_q_volume = _q_int(math.round(volume / _q_volume_unit))36 37var int session_key = 038var float origin = 0.039var float sum_v = 0.040var float sum_pv = 0.041var float sum_ppv = 0.042var float vwap = 0.043var float dev = 0.044var bool ready = false45var int bar_key = 046var float bar_high = 0.047var float bar_low = 0.048var float bar_close = 0.049var float bar_volume = 0.050var int bar_minute = 051var int bar_session = 052// clock: completed chart bar's opening timestamp (America/New_York).53_q_clock_prev_minute = hour(time, "America/New_York") * 60 + minute(time, "America/New_York")54_q_clock_prev_second = _q_clock_prev_minute * 60 + second(time, "America/New_York")55_q_clock_prev_weekday = (dayofweek(time, "America/New_York") + 5) % 756_q_clock_prev_day = int(timestamp("UTC", year(time, "America/New_York"), month(time, "America/New_York"), dayofmonth(time, "America/New_York"), 0, 0) / 86400000)57// Current clock: this chart bar's scheduled close, known without a future bar.58// A native next event after a data gap can carry a later time.59_q_clock_minute = hour(time_close, "America/New_York") * 60 + minute(time_close, "America/New_York")60_q_clock_second = _q_clock_minute * 60 + second(time_close, "America/New_York")61_q_clock_weekday = (dayofweek(time_close, "America/New_York") + 5) % 762_q_clock_day = int(timestamp("UTC", year(time_close, "America/New_York"), month(time_close, "America/New_York"), dayofmonth(time_close, "America/New_York"), 0, 0) / 86400000)63_q_clock_seen = 164int minute_l = na65int second_l = na66int day = na67float high_l = na68float low_l = na69float close_l = na70float volume_l = na71int key = na72int session_l = na73float typical = na74float mean = na75float var_l = na76bool in_session = false77bool late = false78 79minute_l := _q_int(_q_clock_prev_minute)80second_l := _q_int(_q_clock_prev_second)81day := _q_int(_q_clock_prev_day)82high_l := _q_high * 1.083low_l := _q_low * 1.084close_l := _q_close * 1.085volume_l := _q_volume * 1.086key := _q_int(_q_iadd(_q_imul(day, 1440), minute_l))87session_l := _q_int(day)88if minute_l >= session_minute89 session_l := _q_int(_q_iadd(day, 1))90if key != bar_key91 if bar_key != 092 if bar_session != session_key93 session_key := _q_int(bar_session)94 origin := bar_close95 sum_v := 0.096 sum_pv := 0.097 sum_ppv := 0.098 ready := false99 typical := (bar_high + bar_low + bar_close * 1.0) / 3.0 - origin100 sum_v := sum_v + bar_volume101 sum_pv := sum_pv + bar_volume * typical102 sum_ppv := sum_ppv + bar_volume * typical * typical103 if sum_v > 0104 mean := (sum_pv * 1.0) / sum_v105 var_l := (sum_ppv * 1.0) / sum_v - mean * mean106 vwap := origin + mean107 dev := 0.0108 if var_l > 0109 dev := math.sqrt(var_l)110 ready := true111 in_session := bar_minute >= open_minute and _q_iadd(bar_minute, 1) < exit_minute112 if ready and in_session and _q_int(strategy.position_size) == 0 and dev > 0113 if bar_close > vwap + bands * dev114 _q_qty1 = _q_int(clip)115 if _q_qty1 <= 0116 runtime.error("market order quantity must be a positive whole unit")117 _q_pos1 = _q_int(strategy.position_size)118 if _q_pos1 < 0 or _q_pos1 > 0 and _q_qty1 < _q_pos1119 runtime.error("this order would add to or partially reduce a position, so its trade ledger would not be faithful")120 strategy.order("q1", strategy.short, _q_qty1)121 else if bar_close < vwap - bands * dev122 _q_qty2 = _q_int(clip)123 if _q_qty2 <= 0124 runtime.error("market order quantity must be a positive whole unit")125 _q_pos2 = _q_int(strategy.position_size)126 if _q_pos2 > 0 or _q_pos2 < 0 and _q_qty2 < -_q_pos2127 runtime.error("this order would add to or partially reduce a position, so its trade ledger would not be faithful")128 strategy.order("q2", strategy.long, _q_qty2)129 bar_key := _q_int(key)130 bar_minute := _q_int(minute_l)131 bar_session := _q_int(session_l)132 bar_high := high_l133 bar_low := low_l134 bar_volume := volume_l135else136 bar_high := math.max(bar_high, high_l)137 bar_low := math.min(bar_low, low_l)138 bar_volume := bar_volume + volume_l139bar_close := close_l140late := _q_iadd(second_l, 1) >= _q_imul(exit_minute, 60) or minute_l < open_minute141if _q_int(strategy.position_size) < 0142 if close_l <= vwap or late143 _q_qty3 = _q_int(clip)144 if _q_qty3 <= 0145 runtime.error("market order quantity must be a positive whole unit")146 _q_pos3 = _q_int(strategy.position_size)147 if _q_pos3 > 0 or _q_pos3 < 0 and _q_qty3 < -_q_pos3148 runtime.error("this order would add to or partially reduce a position, so its trade ledger would not be faithful")149 strategy.order("q3", strategy.long, _q_qty3)150else if _q_int(strategy.position_size) > 0151 if close_l >= vwap or late152 _q_qty4 = _q_int(clip)153 if _q_qty4 <= 0154 runtime.error("market order quantity must be a positive whole unit")155 _q_pos4 = _q_int(strategy.position_size)156 if _q_pos4 < 0 or _q_pos4 > 0 and _q_qty4 < _q_pos4157 runtime.error("this order would add to or partially reduce a position, so its trade ledger would not be faithful")158 strategy.order("q4", strategy.short, _q_qty4) How it was tested
The published rules, never tuned on the data, with real costs on every fill. Every strategy here is tested the same way.
- Market data
- CME Globex 1-minute bars, Jan 2, 2016 to Jul 31, 2026
- Rules
- As published, with the published parameters, never tuned on this data
- Size
- 1 contract on every trade
- Contract
- The most traded one, rolled as the market moved
- Fees
- The broker's $0.50 a side, plus CME's and the NFA's fees when the window opens
- Slippage
- 1 tick a side on ES, 2 in NQ's regular session and 3 outside it, 1 on other markets, where it was not measured
- Stops and entries
- Tested on 1-second closes and filled at the next bar
- Contracts traded
- ES: 43 contracts, ESH6 to ESU6NQ: 43 contracts, NQH6 to NQU6
- Costs paid
- ES: $9,710 in fees, $68,950 in slippageNQ: $9,217 in fees, $53,115 in slippage
- Warm-up
- None: each contract reads only its own bars
- Flagged days
- ES: NoneNQ: None Days the data holds too few bars for. Flagged, not removed.
Could you pass
a prop firm challenge
with the VWAP reversion strategy?
A backtest says whether a strategy makes money. Our AI runs its trades through the rules of every prop firm account, then tells you which one it would pass and at what size.
No card needed. Free credits every month.
- Most money: Blue Guardian Futures Direct 50K, $5,084
- Best payout odds: Funded Futures Family Straight to Funded 50K, 98%
- Fastest pass: Phidias Express to Live 50K, 11 days
$5,084
Median net across 2,000 simulated runs
- Evaluation
- None
- First payout
- 97%
- Fees paid
- $1,521
Median net across 2,000 simulated runs
Questions about the VWAP reversion strategy
What is the VWAP reversion strategy?
Trade back to the session's VWAP when price has stretched 2 standard deviations away from it. Atlantive backtested it on CME futures from January 2016 to July 2026 after costs.
Is the VWAP reversion strategy profitable on ES futures?
Not in this backtest: on ES futures from January 2016 to April 2025 it lost $99,597 after costs, over 2,758 trades, positive in 2 of 10 years; on NQ it lost $99,047. Buying and holding one ES contract over the same window made $236,212. The average trade was −$36, its 95% interval −$70 to −$4. These are hypothetical results of a backtest, not of trading.
What are the VWAP reversion strategy's rules?
The VWAP is the Globex session's, from its 18:00 New York open, over each one-minute bar's typical price (high + low + close) / 3, with the volume-weighted standard deviation of that price around it. In the day session, a one-minute close above VWAP + 2 deviations sells short and one below VWAP - 2 deviations buys. The position is closed when a one-second close reaches the VWAP, or at 15:45 New York. A new entry may follow an exit the same day. Its parameters are the published ones, never tuned on the data it was tested on.
How was the VWAP reversion strategy backtested?
On CME Globex data from January 2016 to July 2026, one contract, on 1-minute bars, rolled to the most traded contract as the market moved, with the broker's and CME's fees and the slippage measured on each market. Stops and entries were tested on 1-second closes and filled at the next bar. Nothing was fitted to the data.
Can I run the VWAP reversion strategy in TradingView?
Yes. The page carries its Pine Script, written by Atlantive's compiler from the same code the backtest ran, for TradingView's strategy tester. A chart's fills and fees can differ from the backtest's, so test it again on the symbol you trade.
Can I change the VWAP reversion strategy and test it again?
Yes. Rerun it in Atlantive: a new chat opens with the strategy's rules in the box, for you to read, change and send. The agent writes the code, backtests it on the market and window you name, and reports the result with its costs.