MACD crossover strategy: rules and how to test it
By Oalgo · Last reviewed
A MACD crossover strategy acts when the MACD line crosses its average line. A common rule is to enter when the MACD line crosses above the average line, and to exit when it crosses back below. MACD is built from two moving averages, so this is a trend-following rule that reacts after a move has started.
What are the rules of a MACD crossover?
#- Entry: the MACD line (12 and 26) crosses above its 9-period average line. At that moment the histogram moves from below zero to above it.
- Exit: the MACD line crosses back below the average line.
- A common variant uses zero instead: enter when the MACD line crosses above 0, which means the fast EMA has moved above the slow EMA.
- Stop: a Stop Loss as a percentage, for a move against you that comes before the lines cross back.
How do you write this strategy in Oalgo?
#In Oalgo you can tell Oalgo AI your MACD 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 MACD line crosses above the MACD average line. 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 sideways one and a trending one.
- Check the fees and the number of trades. When price drifts sideways the lines cross often.
- Change one setting at a time. If only one exact set of numbers gives a good report, treat it with care.
- Run a forward test on new prices, with simulated funds.
What can a MACD crossover not tell you?
#MACD follows price, so a cross often comes after part of the move has already happened. In a sideways market the two lines cross back and forth and most crosses lead nowhere. A cross does not say how far price will go. The same idea with moving averages is on the moving average crossover page.
Read next
- 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.
- Moving average crossover strategy: rules and how to testA moving average crossover enters when a fast average crosses above a slow one. See the rules, the golden cross and death cross, and how to test them.