Home/Strategies/SMA Crossover

How to Backtest an SMA Crossover Strategy

The simple moving average crossover is one of the oldest systematic trading signals. It is mechanical, easy to understand, and has been studied extensively — which makes it an ideal starting point for learning how to backtest a strategy properly.

What is an SMA Crossover?

A simple moving average (SMA) is the arithmetic mean of closing prices over a defined lookback window. An SMA crossover strategy uses two moving averages — one faster (shorter period) and one slower (longer period). When the fast SMA crosses above the slow SMA, it signals a potential uptrend and generates a buy signal. When it crosses below, it signals a potential downtrend and generates a sell or short signal.

The logic is intuitive: if recent prices are trending higher than the longer-term average, momentum is upward. But the simplicity that makes SMA crossovers appealing is also their limitation — they are inherently lagging indicators, meaning they react to price moves after they have already begun.

Common Parameter Combinations

The most widely referenced SMA crossover is the Golden Cross / Death Cross: the 50-day SMA crossing the 200-day SMA. This pair is watched by institutional traders and frequently cited in financial media.

Other commonly backtested combinations include:

  • 10 / 30 day — faster signals, more trades, higher transaction costs
  • 20 / 50 day — medium-term, good balance for swing trading
  • 50 / 200 day — slow, few trades per year, used for position trading
  • EMA variants — exponential moving averages give more weight to recent prices; test both and compare

The right pair depends on the asset volatility, the timeframe, and your tolerance for holding period length. A 50/200 crossover on a daily chart of SPY will generate fewer than 5 signals per decade; a 10/30 crossover on hourly BTC data may generate hundreds.

Setting Up the Backtest

To backtest an SMA crossover correctly, you need to define:

  1. Universe and timeframe. Which asset(s)? What date range? Use at least 10 years of daily data to capture multiple market cycles.
  2. Entry and exit rules. Do you enter on the close of the crossover bar, or the open of the next bar? The latter is more realistic — you usually cannot execute at the same candle that triggered the signal.
  3. Position sizing. Fixed dollar amount, fixed number of shares, or a percentage of equity? This matters significantly for drawdown calculations.
  4. Transaction costs. Include commissions and a realistic slippage estimate (even 0.05% per side changes results meaningfully on a high-frequency crossover).
  5. Benchmark. Compare against buy-and-hold on the same asset. A strategy that returns 8% annualized but buy-and-hold returns 12% is not useful regardless of how the equity curve looks.

Interpreting the Results

Once the backtest runs, focus on these metrics before drawing conclusions:

  • Sharpe ratio: Return per unit of volatility. Below 0.5 is poor, above 1.0 is good, above 2.0 is exceptional and warrants skepticism.
  • Maximum drawdown: The largest peak-to-trough loss during the test period. A strategy with a 40% max drawdown is psychologically very hard to trade live.
  • Win rate and profit factor: SMA crossover strategies often have win rates of 35–45% — they lose more often than they win, but profitable trades are larger. A profit factor above 1.5 compensates for a low win rate.
  • Number of trades: If there are fewer than 30 trades in the test period, the results are not statistically significant. More trades give more confidence in the metrics.

Common Pitfalls

Overfitting is the biggest risk. If you test 50 different SMA combinations and report the best one, you have data-mined rather than discovered an edge. Validate any parameter set on a hold-out period that was not used during optimization.

Survivorship bias affects equity backtests. If you test SMA crossover on today's S&P 500 constituents going back 20 years, you are testing only the companies that survived — companies that went bankrupt are not in the index anymore. Use a survivorship-bias-free dataset.

Regime dependency is the most underappreciated issue. SMA crossovers work in trending markets and are brutally unprofitable in choppy, ranging environments. Examine results by year — if the strategy only worked during the 2010–2021 bull market, it is not robust.

Try It Yourself

The fastest way to test different SMA parameter combinations without writing code is to describe the strategy in natural language. With QuantPrompt, you can type something like: "Buy when the 20-day SMA crosses above the 50-day SMA on daily SPY data; sell on the reverse crossover. Use 100% of equity per trade." The AI parses the strategy, runs the backtest on historical OHLCV data, and returns a full performance report with equity curve, drawdown chart, and key metrics — no code required.

This makes it practical to iterate quickly: test 10/30 vs. 20/50 vs. 50/200 within minutes, compare Sharpe ratios side by side, and identify which regime each parameter set performs best in.

Frequently Asked Questions