BACKTEST RESULTS

Mean reversion strategy backtest results

SPY daily data, 2016 to 2026: the 20-day MA, 3% envelope rule, long and short, lost 34.4% after costs over 86 trades, winning 46.5% of them, against +277.8% for holding SPY. Long only it made 16.7%. The best of 5 runs was 20-day MA, 3% envelope on SPY, long only: +16.7%, held-out survived. Every run, every trade and the script are on this page.

SPY · daily data · 20-day MA, 3% envelope · long and short
Net after costs
-34.4%
Holding SPY
+277.8%
Trades
86
Win rate
46.5%
Profit factor
0.68
Max drawdown
40.4%
Held out, last third: did not survive
Long only: +16.7% on 44 trades, held-out survived
4 January 2016 to 23 October 2026
  • Checked 25 October 2026
  • Alpaca daily data since 2016
  • 0.05% commission + 0.025% slippage per fill
  • last third of the history held out
  • 5 runs, 486 trades
  • Updated 1 November 2026

The short answer

Answers here: Does mean reversion work on the index? · 3% or 2% envelope? · What is the win rate? · Long only, or both ways?

SPY daily data, 4 January 2016 to 23 October 2026, long and short: 86 trades, lost 34.4% after costs, 46.5% of trades won, profit factor 0.68, worst drawdown 40.4%, 20% of the time in the market. Holding SPY returned +277.8% over the same period.

Held out on its own, the last third (16 March 2023 to 23 October 2026) lost 2.6% on 22 trades: it did not survive its held-out period.

Long only, the same rule made 16.7% on 44 trades (59.1% won, profit factor 1.41, held-out survived): the short side cost 51.0 points of return in a period when SPY rose 277.8%.

Across all 5 runs on this page, 2 made money after costs, 2 survived the held-out third, and 0 beat holding the symbol.

The best run was 20-day MA, 3% envelope on SPY, long only: +16.7% net on 44 trades, profit factor 1.41, worst drawdown 20.5%, held-out survived. The tester's verdict on it reads "made money, but could be luck".

One symbol's past after modelled costs is not a forecast. Prices are split-adjusted and not dividend-adjusted, so every return here is a price return; the period includes a long rise with two sharp falls, and a rule that is often long did well for that reason as much as any other. These are research results, not investment advice.

What the script does

MA Envelope Reversion Strategy, from the strategy library.

A moving-average envelope: goes long when the close crosses back above a band 3% below the 20-day average and goes short when it crosses back below a band 3% above it; the trade closes when the close crosses the average itself. A stop sits 2 ATR away. A tighter 2% band was run on SPY, and long-only versions on SPY and QQQ. The RSI and Bollinger pages test the other two common mean-reversion rules.

The indicator itself, with its Pine code drawn on real market data: Mean Reversion.

The numbers, run by run

Net and holding the symbol are after costs over the same period. Held-out is the verdict on the last third of the history judged alone: survived, decayed, did not survive, or too few trades to judge.

SymbolTimeframeSettingsDirectionTradesWin rateNetHoldingProfit factorMax drawdownHeld-out
SPYdaily20-day MA, 3% envelopelong and short8646.5%-34.4%+277.8%0.6840.4%did not survive
SPYdaily20-day MA, 2% envelopelong and short14951.7%-32.0%+277.8%0.7844.8%did not survive
QQQdaily20-day MA, 3% envelopelong and short14751.0%-57.8%+542.3%0.6761.3%did not survive
SPYdaily20-day MA, 3% envelopelong only4459.1%+16.7%+277.8%1.4120.5%survived
QQQdaily20-day MA, 3% envelopelong only6065.0%+2.9%+542.3%1.0833.3%survived

Year by year

20-day MA, 3% envelope on SPY, long and short, the same rule long only, and SPY itself, each calendar year after costs. A partial first or last year counts the sessions it has.

Year20-day MA, 3% envelope, long and short20-day MA, 3% envelope, long onlyHolding SPY
2016-2.0%+2.1%+11.2%
20170.0%0.0%+18.5%
2018+5.3%+2.8%-6.9%
2019-8.2%-0.2%+28.6%
2020-8.5%+13.4%+15.1%
2021-2.9%+1.7%+28.8%
2022-19.5%-17.1%-19.9%
2023-1.8%+9.0%+24.8%
2024+6.1%+3.5%+24.0%
2025-1.3%+4.5%+16.6%
2026-6.9%-2.3%+11.2%

Every trade

The 86 trades of 20-day MA, 3% envelope on SPY, long and short, oldest first: side, entry and exit days, fill prices after slippage, and the return after both commissions. The other runs' trades open below.

SideInOutEntryExitReturn
short2016-03-092016-04-08199.30205.40-3.2%
long2016-06-292016-07-01204.88209.30+2.1%
short2016-07-142016-08-26216.34217.98-0.9%
short2018-01-192018-01-23279.72282.83-1.2%
short2018-01-262018-02-05284.19273.55+3.6%
long2018-02-152018-02-26271.67275.85+1.4%
long2018-03-272018-04-13266.25267.33+0.3%
long2018-10-172018-10-23280.52270.86-3.5%
long2018-11-012018-11-07271.70277.48+2.0%
long2018-11-272018-11-29266.42273.63+2.6%
long2019-01-022019-01-08246.05256.75+4.2%
short2019-01-252019-02-05265.53272.71-2.8%
short2019-02-082019-02-19268.67277.65-3.4%
long2019-05-152019-05-31281.67276.12-2.1%
long2019-06-052019-06-06282.41283.21+0.2%
short2019-06-242019-07-12294.15300.02-2.1%
long2019-08-092019-08-14292.66285.80-2.4%
long2019-08-192019-08-22292.26293.15+0.2%
long2019-10-042019-10-14291.22295.84+1.5%
long2020-03-272020-04-07253.36274.13+8.1%
short2020-04-222020-04-29278.27294.35-5.9%
short2020-05-042020-05-14280.66279.02+0.5%
short2020-05-202020-06-03295.74310.32-5.0%
short2020-06-122020-06-16308.15315.56-2.5%
long2020-06-302020-07-02304.07314.14+3.2%
short2020-07-172020-08-06321.76333.47-3.7%
short2020-08-102020-08-26334.97345.26-3.2%
short2020-09-012020-09-02350.11356.06-1.8%
short2020-09-042020-09-09346.03337.64+2.3%
long2020-09-282020-10-02333.31331.61-0.6%
short2020-10-192020-10-27348.52339.84+2.4%
long2020-11-042020-11-05340.95349.14+2.3%
short2020-11-232020-12-17357.18372.26-4.3%
short2021-04-072021-05-12405.83411.34-1.5%
long2021-09-232021-10-01439.96428.53-2.7%
long2021-10-042021-10-15433.12444.64+2.6%
short2021-10-282021-11-05455.34469.41-3.2%
short2021-11-102021-11-29465.45464.20+0.2%
long2021-12-032021-12-08459.29468.57+1.9%
long2022-02-012022-02-03450.84450.83-0.1%
long2022-02-282022-03-08432.14418.47-3.3%
long2022-03-102022-03-17422.64433.47+2.5%
short2022-03-242022-03-29445.81461.44-3.6%
short2022-04-012022-04-12453.20443.20+2.1%
long2022-04-292022-05-02423.71410.72-3.2%
long2022-05-052022-05-05424.64410.01-3.5%
long2022-05-182022-05-19403.61387.82-4.0%
long2022-05-242022-05-27392.67407.82+3.8%
short2022-06-012022-06-10415.04394.99+4.7%
long2022-06-272022-07-08391.16387.16-1.1%
short2022-07-252022-07-29395.64411.09-4.0%
short2022-08-102022-08-11418.68424.63-1.5%
short2022-08-222022-08-23416.94413.01+0.8%
long2022-09-092022-09-13402.84401.71-0.4%
long2022-09-152022-09-22393.07373.55-5.1%
long2022-10-052022-10-10373.49360.52-3.6%
long2022-10-142022-10-19368.63368.880.0%
short2022-10-282022-11-04379.77377.10+0.6%
short2022-11-182022-12-01397.62409.35-3.0%
short2022-12-062022-12-07399.31393.01+1.5%
long2022-12-222023-01-09383.16390.26+1.8%
short2023-01-192023-02-01389.24412.81-6.2%
short2023-02-072023-02-21408.76403.17+1.3%
long2023-03-152023-03-22385.98398.62+3.2%
short2023-04-062023-04-26406.66406.83-0.1%
short2023-06-212023-07-12436.07446.51-2.5%
long2023-09-262023-09-27429.21423.28-1.5%
long2023-09-292023-10-11431.81435.53+0.8%
long2023-10-312023-11-03416.29432.99+3.9%
short2023-11-292023-12-12457.03462.98-1.4%
short2023-12-182023-12-26470.86476.57-1.3%
long2024-04-232024-04-30501.93508.42+1.2%
short2024-05-212024-05-31529.14523.72+0.9%
long2024-08-092024-08-14529.95542.72+2.3%
short2024-08-232024-09-06559.38550.08+1.6%
long2025-03-062025-03-07575.63565.51-1.9%
long2025-03-182025-03-25564.95575.15+1.7%
long2025-04-102025-04-25532.38546.50+2.6%
short2025-05-222025-06-10582.50603.24-3.7%
short2025-07-082025-07-23621.18633.35-2.1%
long2025-11-242025-11-26662.87677.42+2.1%
long2026-03-242026-03-27651.49635.38-2.6%
long2026-04-012026-04-07654.05656.47+0.3%
short2026-04-302026-05-06714.44733.79-2.8%
short2026-05-132026-05-28738.26754.73-2.3%
short2026-08-062026-08-25770.01766.37+0.4%

The script

Pine v6, exactly as it ran for 20-day MA, 3% envelope on SPY, long and short. The variants change only the inputs listed in the table.

//@version=6
strategy("MA Envelope Reversion Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100000, commission_type=strategy.commission.percent, commission_value=0.05, slippage=1, margin_long=0, margin_short=0)

src      = input.source(close, "Source", group="Setup")
len      = input.int(20, "MA length", minval=1, group="Setup")
pct      = input.float(3, "Envelope %", minval=0.1, step=0.1, group="Setup")
useLong  = input.bool(true, "Trade longs", group="Direction")
useShort = input.bool(true, "Trade shorts", group="Direction")
atrLen   = input.int(14, "ATR length", minval=1, group="Risk")
stopMult = input.float(2, "Stop (ATR multiples, 0 = off)", minval=0, step=0.5, group="Risk")

basis = ta.sma(src, len)
upper = basis * (1 + pct / 100)
lower = basis * (1 - pct / 100)
atr   = ta.atr(atrLen)

longSig   = ta.crossover(close, lower) and barstate.isconfirmed
shortSig  = ta.crossunder(close, upper) and barstate.isconfirmed
exitLong  = ta.crossover(close, basis) and barstate.isconfirmed
exitShort = ta.crossunder(close, basis) and barstate.isconfirmed

pU = plot(upper, "Upper envelope", color=color.new(#E5484D, 20), linewidth=1)
pL = plot(lower, "Lower envelope", color=color.new(#16A56A, 20), linewidth=1)
plot(basis, "Basis", color=color.new(#A3A39E, 0), linewidth=1)
fill(pU, pL, color=color.new(#A3A39E, 94), title="Envelope fill")

if longSig and useLong
    strategy.entry("Long", strategy.long)
    strategy.exit("Long stop", "Long", stop=stopMult > 0 ? close - stopMult * atr : na)
if shortSig and useShort
    strategy.entry("Short", strategy.short)
    strategy.exit("Short stop", "Short", stop=stopMult > 0 ? close + stopMult * atr : na)
if exitLong
    strategy.close("Long")
if exitShort
    strategy.close("Short")

How it was tested

Alpaca daily data since 2016, 0.05% commission and 0.025% slippage on every fill, the last third of the history held out, textbook settings and nothing tuned. The engine, fills and what it does not model are written out once, in data and methodology.

Run the Mean reversion strategy on your own symbol, free

Describe the rule in your own words or paste the script. The Free plan writes the Pine v6 script with the AI, runs it on any US stock or ETF with the same costs and the same held-out check, and shows every trade on the chart. No card.

Every strategy tested

Seventeen popular rules through the same engine, the same costs and the same held-out check, with every trade listed. Next: Bollinger Bands strategy, RSI strategy, Stochastic strategy.

Questions

Does the Mean reversion strategy work?

SPY, daily data, 2016 to 2026, long and short: 20-day MA, 3% envelope lost 34.4% after costs over 86 trades (46.5% won, profit factor 0.68) against +277.8% for holding SPY, and the held-out third did not survive. Long only it made 16.7%. Across all 5 runs on the page, 2 made money after costs, 2 survived their held-out third and 0 beat holding the stock.

What is the win rate of the Mean reversion strategy?

From 46.5% to 65.0% across the 5 runs. The classic setting, 20-day MA, 3% envelope on SPY long and short, won 46.5% of 86 trades. The win rate alone does not decide the result: that run's profit factor was 0.68, so its losers outweighed its winners, and the net return was -34.4%.

What are the best Mean reversion settings?

Of the 2 settings tested, 20-day MA, 3% envelope on SPY (long only) did best: +16.7% net, profit factor 1.41, held-out survived. That is the best of 5 tries on 10.8 years of daily data of one symbol, which is already a fitted number. A setting that works on one symbol or one period only is a coincidence, not a setting; run it on your own symbol and timeframe before trusting it.

Does the Mean reversion strategy beat holding the stock?

0 of the 5 runs did. SPY itself returned +277.8% between 4 January 2016 and 23 October 2026, so a rule that is out of the market part of the time has a lot to make up; what a timing rule usually gets you is a smaller drawdown, not a bigger return. The classic run's worst drawdown was 40.4% with 20% of the time in the market.

Did the Mean reversion strategy hold up out of sample?

The last third of every run's history (16 March 2023 to 23 October 2026 for the lead run) was judged on its own, with no fitting on it: 2 of 5 runs survived, 0 decayed, 3 did not survive and 0 had too few trades there to judge. Survived means a positive Sharpe ratio on the held-out part at least half the fitted period's; it is a check on one later stretch, not a forecast.

How was this tested?

With the free Alpha Charts tester's own engine: the Pine v6 scripts on this page, run on Alpaca daily data since 2016, split-adjusted and not dividend-adjusted, one position at a time with the whole account, fills at the next candle's open, a commission of 0.05% and slippage of 0.025% on every fill, the last third of the history held out. The settings are the textbook ones and every variant is stated; nothing was tuned to make the page look better.

Every number on this page is the output of the Alpha Charts backtest engine on 25 October 2026, on Alpaca market data; the scripts are the strategy library's templates, shown as they ran. Symbols are US-listed ETFs and stocks; results are price returns after the costs stated. Past results are not a forecast and nothing here is investment advice. TradingView and Pine Script belong to TradingView, Inc.; Alpha Charts is not affiliated with it.