72lab
Sign up free
Indicators in Practice & Backtesting· Lesson 3 of 7· 8 min

Backtesting a Moving Average Strategy

Test your rules against historical data: return, win rate and maximum drawdown, and you can't skip any of them.

This lesson is free: sign up for an account to use the interactive simulation

Every lesson has an interactive simulation you can drag and play, plus a quick quiz. Sign up free to use them and save your progress automatically. Here is the text version of this lesson.

Not sure yet? Try the first lesson (no sign-up needed)「Indicator Confluence」。

Text version · Indicators in Practice & Backtesting, lesson 3: “Backtesting a Moving Average Strategy”

Test your rules against historical data: return, win rate and maximum drawdown, and you can't skip any of them.

Put the rules to the test of history

A backtest uses historical data to simulate "what would have happened if I'd followed the rules strictly back then." Check the return on the report card, but also the maximum drawdown, win rate and number of trades, and compare with "buy and hold."

Don't use information you didn't have at the time

A signal calculated from the close can only fill at the next bar's open. Filling a same-day close signal at the same day's open is look-ahead bias, and it makes a backtest look absurdly good.

Don't forget trading costs

Every trade costs a commission, and there's slippage too. The more often you trade, the more costs eat: a strategy with a decent gross return may stop making money once costs are subtracted.

Key takeaways

  • Backtest = simulating what would have happened if you'd traded strictly by the rules on historical data.
  • Along with return, always check maximum drawdown and the number of trades, and compare with buy-and-hold.
  • Include fees and slippage. If a signal is calculated from the close, you can only fill at the next candle's open; don't use "future data".
  • A good-looking backtest doesn't mean future profits. It's just the first filter for weeding out bad ideas.

Try it yourself

You can do these exercises in this lesson's interactive simulation:

  1. Keep "Trending" and 5 / 20, then click "Run backtest": did the strategy beat buy and hold? Which had the smaller maximum drawdown?
  2. Look at the example card below: A returns 30% with a 50% drawdown, B returns 20% with a 10% drawdown. By "return ÷ drawdown," which is better?
  3. Turn on "Look-ahead bias": how much more does the cheating version make? Hover over a trade to see on which bar it "peeked" at the close.
  4. Switch to "Ranging," backtest again, and push fees to 0.3%: how do back-and-forth trading costs eat up the return?

Quiz and explanations

1. Strategy A returns 30% with a 50% maximum drawdown; strategy B returns 20% with a 10% maximum drawdown. Which is usually better on a risk-adjusted basis?
Answer: B.B earns far more return for each unit of drawdown it endures.
2. In a backtest, a signal is calculated from today's close but filled at today's open. What's the mistake?
Answer: It uses future data.At the open, you don't yet know the close.
3. The fee is 0.1% per side, and the strategy completes 200 trades a year (each one a buy and a sell). Simply adding up the fees, roughly how much return do they eat?
Answer: About 40%.200 trades × 2 sides × 0.1% ≈ 40%. Ignore costs in a backtest and high-frequency strategies look far better than they are.

Terms in this lesson

  • backtest (Backtest): Simulating rule-based trading on historical data to see how a strategy would have done.
  • commission (Commission): The fee you pay your broker each time you buy or sell, which comes straight out of your profit.
  • death cross (Death Cross): A short-term moving average (or an indicator's fast line) crossing below a long-term one (the slow line).
  • equity curve (Equity Curve): A line showing how account value changes over time.
  • golden cross (Golden Cross): A short-term moving average (or an indicator's fast line) crossing above a long-term one (the slow line).
  • look-ahead bias (Look-Ahead Bias): Accidentally using data in a backtest that couldn't have been known at the time, which inflates the results.
  • maximum drawdown (Max Drawdown): The biggest drop from an equity peak to the lowest point that follows.
  • profit factor (Profit Factor): Total profit from winning trades ÷ total loss from losing trades.
  • slippage (Slippage): The difference between the price you expected and your actual average fill, which happens when a large market order eats through several price levels.
  • stop-loss (Stop Loss): Automatically closes a position when price moves against you to a preset level, capping your maximum loss.
  • win rate (Win Rate): The share of all trades that made money.
Backtesting a Moving Average Strategy (Indicators in Practice & Backtesting) · 72lab