RealTest Strategies / SPY ETF Mean Reversion Strategy

SPY ETF Mean Reversion Strategy

A RealTest mean-reversion strategy that trades a single instrument, the SPY ETF. It buys the broad market when it pulls back and sells into the recovery, so there is no stock picking and no single-company risk. The code comes in RealTest and TradingView Pine Script. Tested on data back to 2000 with costs modeled, and trading live since November 2024.

Live traded since Nov 2024Trading costs included Survivorship-bias-free data
$100k$300k'02'04'06'08'10'12'14'16'18'20'22'24'26 Live $776k $592k
Strategy SPY buy & hold
Sharpe ratio?
0.7
+46%vs SPY 0.48
Best year?
+24.1%
SPY best: 27.0% in 2003
Max drawdown?
-27.8%
44% smallervs SPY -49.9%

Validated four ways

See how each test is run →

Live market performance
Performs in real market conditions since 2024-11-11
Verified
Statistical validation
Validated across in-sample & out-of-sample data
Passed
Walk forward analysis
Tests robustness across unseen data
Passed
Monte Carlo stress test
Resilient against 1,000+ sequence risk simulations
Passed

What happened in every crash

CrisisDatesStrategySPYSame $100k in
Dotcom crash Mar 2000 – Oct 2002 -3.1% -41.8%
2008 financial crisis Oct 2007 – Mar 2009 -15.0% -49.9%
COVID-19 crash Feb 2020 – Mar 2020 -4.1% -28.7%
2022 bear market Jan 2022 – Oct 2022 -2.9% -21.3%

Strategy monthly returns

JanFebMarAprMayJunJulAugSepOctNovDecYear
20001.2-0.20.5-1.63.4-0.1-3.40.8-4.3-1.4-0.11.7-3.6%
20010.0-4.23.20.01.42.31.1-1.7-10.00.52.82.5-2.9%
2002-1.63.7-0.7-4.33.3-3.28.80.6-1.46.70.5-1.510.4%
2003-2.4-1.81.96.40.5-2.81.9-0.7-2.64.02.50.06.6%
2004-0.10.9-0.21.71.50.0-0.01.6-0.91.70.61.08.1%
2005-0.90.8-1.6-0.00.00.21.02.1-0.3-0.80.01.41.8%
20063.31.02.12.1-0.6-0.41.60.01.21.52.91.316.9%
20070.90.40.30.04.11.0-4.44.90.0-0.74.21.012.0%
2008-5.80.02.74.34.8-2.82.41.65.3-9.9-4.80.6-2.9%
20092.7-11.5-1.38.63.1-1.02.03.31.8-4.63.03.48.5%
2010-2.42.30.0-0.2-0.3-5.03.60.80.00.0-0.80.0-2.3%
20110.52.40.31.32.4-1.42.5-7.63.91.61.41.99.0%
20120.00.01.80.8-2.82.20.31.40.61.71.62.610.6%
20131.90.32.20.90.02.70.3-0.50.20.53.32.515.2%
2014-2.00.12.60.31.92.02.40.70.8-1.10.00.88.8%
20152.10.02.10.01.0-1.4-0.45.84.32.30.51.118.7%
2016-5.21.60.01.62.60.50.0-0.03.30.00.10.34.5%
20171.50.6-1.10.90.0-0.30.90.60.00.00.00.03.0%
2018-0.3-6.30.70.82.2-0.10.91.80.1-2.9-0.9-3.2-7.3%
20190.00.01.30.0-1.53.01.92.0-0.3-1.10.01.87.3%
2020-0.4-4.69.22.59.31.63.40.4-0.4-4.34.40.021.9%
2021-1.76.51.71.52.22.23.00.0-1.31.70.84.022.3%
2022-2.8-1.22.40.32.5-3.05.5-5.2-1.00.01.11.5-0.4%
20234.8-2.43.20.94.51.70.4-1.10.1-0.30.20.613.1%
20242.40.01.8-1.6-0.12.0-0.33.70.90.25.1-0.714.2%
20253.20.2-5.012.00.62.70.03.11.01.22.80.924.1%
20260.00.9-2.60.50.03.1-0.32.00.03.7%

Strategy overview

Why it works on the index

The whole market swings on short-term fear and relief just as individual stocks do. When SPY drops sharply over a few days, a lot of that selling is emotional rather than a change in the long-term trend, and the index tends to recover once the pressure eases. The strategy buys those pullbacks and sells into the bounce, working the same overreaction that mean reversion uses on single stocks, but on the broad market where the trend is steadier.

How it was tested

Trading one instrument removes a lot of the ways a backtest can mislead. There is no survivorship bias to correct for and no thin-stock fills to worry about, because SPY is the most liquid instrument in the market. Commissions on US ETFs are effectively zero and slippage is tiny, and both are still included in the results. The rule is simple, uses few parameters, and was checked with walk-forward analysis and Monte Carlo simulation, shown on this page.

How it fits your trading

This is one of the simplest strategies to run. It trades a single, liquid instrument, so it scales from a small account to a large one without changing anything, and the near-zero costs mean very little is lost to friction. Because it comes in both RealTest and TradingView Pine Script, you can run it on either platform. It works well as a steady base position next to strategies that trade individual stocks.

Specification

StyleMean reversionUniverseSPY ETFTimeframeDailySideLongAverage hold6 trading daysTrade frequency1.0 per monthEntry executionMarket on openExit executionMarket on openDataNorgate Data (US Stocks Platinum) SoftwareRealTestCommission$0 commission on US ETFsSlippage0.005% per sideSPY benchmarkNo fees applied (favors SPY)

What you get

RealTest by MHP Trading logo
RealTest strategy code (.rts)
Complete RealTest (.rts) strategy code. Import, backtest, and modify.
Trading strategy rules plain text document
Plain text rules
Trade it on any platform without reading the code.
TradingView Pine Script logo
TradingView Pine Script
Full Pine Script code. Implements the exact same strategy rules for your charts.

Quick start & live trading

RealTest trading software logo
Quick start guide
From download to first backtest in 1 minute
1
You download the .rts file
Click download
2
You open it in RealTest
File → Open → Select file
3
You import symbols
Click import
4
You run the backtest
Click test
OrderClerk automated trading execution interface
Daily live trading
For RealTest automated execution
1
Open OrderClerk
Click 'Connect to IB'
2
Import signals
Click 'Import' in RealTest
3
Generate orders
Click 'Orders' in RealTest
4
Execute trades
Click 'Place Orders'

What traders say

Buying a SetupAlpha strategy didn't save me money, it saved me research time. I estimate it replaced 70–90 hours of development, debugging, and validation. Even if I never trade the strategy exactly as delivered, the research process was worth the investment.

Roman Blackwood
Roman Blackwood
Founder of AI in Trading (+13K subscribers)

I've been using a strategy from SetupAlpha and I'm really impressed with its elegance and stability. The unique approach gives me a fresh perspective and ideas I can apply to other strategies I'm developing. I'm currently working on integrating it into my suite of trading strategies.

TradeQuantiX
TradeQuantiX
Multi-country systematic trader (+4.7K subscribers)

I traded discretionary for over a decade and kept putting off going systematic because I did not know where to start. Having a finished, tested system to take apart was what finally got me moving.

Daniel
Daniel
Crypto trader

I have run it live since 2024 and it is still in my portfolio. It also changed how I test the systems I build myself.

Systematic Traders
Systematic Traders
Algo trader & Substack writer (+6.4K subscribers)

FAQ

What is SPY ETF Mean Reversion Strategy?
A RealTest mean-reversion strategy that trades a single instrument, the SPY ETF. It buys the broad market when it pulls back and sells into the recovery, so there is no stock picking and no single-company risk. The code comes in RealTest and TradingView Pine Script. Tested on data back to 2000 with costs modeled, and trading live since November 2024.
Why should this edge keep working?
The whole market overreacts to short-term fear just as individual stocks do. When SPY falls sharply over a few days, much of that selling is emotional rather than a real change in trend, and the index usually recovers once the pressure eases. The strategy buys those pullbacks and sells into the bounce, using the same overreaction that mean reversion relies on, but on the broad market where the trend is steadier. Short-term mean reversion in equity indices is a well-studied effect.
What is RealTest and what software do I need?
RealTest is a backtesting and trade automation platform for systematic traders, built by Martin Parker at MHP Trading. Each strategy comes as an .rts file you import directly. To trade it live you add OrderClerk and an Interactive Brokers account.
How was this backtested?
Survivorship-free Norgate data from January 2000 to the present, with out-of-sample walk-forward analysis and over 1000 Monte Carlo simulations to test stability.
Are transaction costs included?
Yes. The results include Interactive Brokers commissions, slippage of 0.005% per side, so the equity curve is after costs.
When did live trading start?
Live trading started in November 2024. The equity curve shows the backtest from 2000 and real performance from that point on.
What's included in the download?
RealTest .rts file (complete source). Plain-text trading rules. TradingView Pine Script. Full documentation with parameter explanations.
How does it compare to SPY?
The chart at the top plots this strategy against SPY, the S&P 500 ETF, from 2000 with both starting at $100,000. A metrics table lists the exact numbers side by side: Sharpe, Sortino, net profit and worst year, for the strategy and for SPY over the same period.
Can I modify the code?
Yes. You get the complete source code with a perpetual license, so you can adjust parameters, change position sizing, combine it with other systems, or use it as a starting point for your own research.
What market data do I need?
Norgate Data (recommended) for survivorship-free US equities. Yahoo Finance works for basic testing but lacks delisted stocks. The backtest results shown here use Norgate Platinum.
Can I automate execution?
RealTest to OrderClerk to Interactive Brokers. Generate signals daily in RealTest, execute automatically via OrderClerk to IBKR. Setup course available.
Can I ask questions about the code or the strategy?
Yes. Email setupalpha.capital@gmail.com and you will get an answer, before or after you buy.

Changelog

2024-11-11Rules finalised. Live tracking starts.

No rule changes since.

Portfolio growth since 2000
676.1%
SPY same period: 492.5%
$1,490one-time
Instant download
MetricStrategySPY
Sharpe0.70.48
ROR8.09%
Sortino0.410.46
MAR0.29
Net profit$676k$492k
Expectancy0.66%
Max exposure104.95%100%
Worst year-7.3%-33.2%

Download the complete strategy now

Active Script - C:\REALTEST\Strategies\spy_etf_mean_reversion.rts
SPY ETF Mean Reversion Strategy full RealTest script
Trading strategy rules plain text document
Plain text rules
Trade it on any platform without reading the code.
SPY ETF Mean Reversion Strategy
$1,490one-time
Instant download