Moving average crossover strategy: rules and how to test
By Oalgo · Last reviewed
A moving average crossover strategy uses two moving averages of different lengths. A common rule is to enter when the fast one crosses above the slow one, and to exit when it crosses back below. It follows a trend after the trend has started.
What are the rules of a moving average crossover?
#- Entry: the fast average crosses above the slow average, for example an EMA over 9 candles crossing above an EMA over 21 candles.
- Exit: the fast average crosses back below the slow average.
- Stop: a Stop Loss as a percentage, for a move against you that comes before the averages cross back.
What are the golden cross and the death cross?
#The golden cross is a crossover of a 50-period average above a 200-period average, usually simple averages (SMA). The death cross is the opposite: the 50 crosses below the 200. They are the same rule with long settings, so they happen rarely and each one comes late. A 200-period average has no value until 200 candles exist.
How do you write this strategy in Oalgo?
#In Oalgo you can tell Oalgo AI your moving average crossover rule in your own words, check the rule it builds, and test it. After testing, if you choose, you Go Live with your own Live Strategy on your own Venue Account at a Supported Venue.
For example, you could tell Oalgo AI: "Enter when the 9-period EMA crosses above the 21-period EMA. Exit when it crosses back below. Use a 1% Stop Loss and a 3% exit target." These numbers are examples to change. A Live Strategy needs a stop on each side it can enter, and an exit target is optional. The example names both.
How do you test this strategy honestly?
#- Run a backtest on more than one date range, including a range you did not tune the settings on.
- Check the fees. A crossover that flips often opens many trades, and each one pays them.
- Try nearby settings, such as 8 and 20, then 10 and 22. If the report falls apart when a setting moves a little, the first result may be overfitting.
- Run a forward test on new prices, with simulated funds, before you decide anything.
What can a moving average crossover not tell you?
#Averages follow price, so every cross comes after the move has begun, and part of it is already gone. In a sideways market the two lines cross back and forth, and most of those crosses lead nowhere. A cross does not say how far price will go or whether it will keep going. The two lengths change when the rule acts, and no pair of lengths fits every market.
Read next
- Moving averages: SMA and EMA explainedA moving average smooths price into one line. Learn how the SMA and EMA are calculated, how they differ, and how to use them in your own rules.
- MACD indicator explained: how to read itThe MACD indicator is the gap between a fast and a slow moving average. See how it is calculated, how to read the lines and histogram, and how to test it.