Strategies we backtested MACD divergence strategy

Tested by BacktestingMax

MACD divergence strategy backtest

Does MACD divergence make money?

Mostly no: with the standard rules, only 4 out of 12 tests of MACD divergence made money from 2007 to 2025. We tested 6 markets (4 currency pairs, gold and silver), each on 1-hour and 4-hour charts, after trading costs. MACD is an indicator that measures momentum, how fast and in which direction price is moving. A divergence is when price and MACD point in different directions. In a bullish divergence, price makes a lower low, but MACD makes a higher low below zero. We bought when the MACD line then crossed above its signal line. A bearish divergence is the opposite, and we sold short (sell first, to profit from a fall). Only USD/JPY made money in both the older years (2007–2019) and the newer years (2020–2025): +66.2% on 1-hour charts and +15.9% on 4-hour charts. Over all 12 tests, the average trade lost 0.037R. R is the result of a trade divided by the amount it risked, which was 1% of the account when the trade opened. Daily charts gave only 26 to 35 trades per market in 19 years, too few to judge. On stock indices from 2019 to 2025, 2 out of 6 tests on 1-hour and 4-hour charts made money. They were the Nasdaq 100 on 1-hour charts (+1.8%) and the DAX on 4-hour charts (+8.6%), but the DAX made only 79 trades, too few to judge.

18 backtests 2007–2025 Trading costs included Tested 23 November 2026

Where it worked 18 backtests
Made money
4
of 18 tests, using the standard rules
Made money in both periods
2
2007–2019 and again 2020–2025
Best backtest
+66%
USD/JPY, 1-hour chart: account growth 2007–2025
Only trade with the 200 EMA trend
0
tests made money in both periods, compared with 2 using the standard rules

Made money in both periods

  • USD/JPY, 1-hour
  • USD/JPY, 4-hour

The results

Results on every market

Each box shows one backtest of the MACD divergence strategy using the standard rules, from 2007 to 2025, after trading costs: the % result, and a small chart of the account balance. The solid line is the account balance and the dashed line is the starting balance. Green results made money; red results lost money. Under each result: whether it made money in both 2007–2019 and 2020–2025, or passed all four of our checks (see "How a test passes" further down).

Market 1-hour 4-hour daily
EUR/USD −55% Lost money +7% Made money overall, lost in one period +7% Too few trades
GBP/USD −9% Lost money +0.5% Made money overall, lost in one period −14% Too few trades
USD/JPY +66% Made money in both periods +16% Made money in both periods −5% Too few trades
AUD/USD −45% Lost money −8% Lost money +3% Too few trades
Gold −31% Lost money −12% Lost money +3% Too few trades
Silver −67% Lost money −30% Lost money +14% Too few trades
All the numbers, test by test
Market Chart Trades Win rate Profit factor Result Max drawdown 2007–2019 2020–2025 Monte Carlo drawdown Trading costs
EUR/USD 1-hour 826 30.8% 0.88 −55.2% −64.4% −28.0% −37.8% −68.6% $1,560
EUR/USD 4-hour 197 35% 1.06 +7.3% −15.7% −3.5% +11.2% −23.7% $201
EUR/USD daily 33 42.4% 1.38 +6.7% −4.3% +7.4% −0.6% −7.9% $13
GBP/USD 1-hour 867 34.1% 0.99 −8.5% −34.6% −6.1% −2.5% −50.3% $2,381
GBP/USD 4-hour 207 34.3% 1.00 +0.5% −14.4% −2.3% +2.8% −26.4% $269
GBP/USD daily 35 17.1% 0.42 −14.1% −16.8% −7.5% −7.2% −17.8% $15
USD/JPY 1-hour 758 36.8% 1.11 +66.2% −32.5% +21.4% +37.0% −37.0% $2,719
USD/JPY 4-hour 183 36.6% 1.13 +15.9% −14.0% +11.9% +3.5% −21.6% $259
USD/JPY daily 35 28.6% 0.78 −4.9% −12.2% −8.8% +4.3% −12.9% $17
AUD/USD 1-hour 800 32.2% 0.90 −44.6% −49.1% −22.4% −28.7% −62.9% $2,108
AUD/USD 4-hour 228 32.9% 0.94 −8.1% −23.5% −6.1% −2.2% −30.1% $327
AUD/USD daily 28 39.3% 1.18 +3.1% −7.7% +7.2% −3.9% −8.7% $15
Gold 1-hour 816 33.5% 0.94 −31.0% −50.6% −30.0% −1.5% −55.8% $2,818
Gold 4-hour 206 32% 0.91 −11.8% −27.0% −1.2% −10.8% −29.9% $418
Gold daily 26 38.5% 1.22 +3.0% −4.6% +1.4% +1.5% −7.4% $19
Silver 1-hour 798 31.8% 0.79 −67.3% −70.7% −66.2% −3.2% −74.0% $3,837
Silver 4-hour 197 29.4% 0.73 −29.6% −35.7% −20.6% −11.3% −38.6% $855
Silver daily 34 50% 1.98 +14.1% −4.1% +11.4% +2.4% −5.6% $65

Profit factor is the money won divided by the money lost. Above 1 means the test made money. Max drawdown is the biggest fall from the highest balance. 2007–2019 and 2020–2025 show the result in each period on its own. Monte Carlo drawdown: we shuffled the trades into a random order 1,000 times; in 95% of those runs, the worst drawdown was this number or less. Result is the change in the account, with the risk of each trade set to 1% of the account at that time.

The account balance

The best test and the middle test

Best test USD/JPY, 1-hour chart +66.2% from 2007 to 2025
Middle test (median): half of the 18 did better, half did worse USD/JPY, daily chart −4.9% from 2007 to 2025

What we found

What the 18 backtests show

  1. USD/JPY was the only market with a clearly positive average trade. On 1-hour and 4-hour charts together, its 941 trades made +0.080R on average, and 36.8% of them won. The other 5 markets together made 5,142 trades with an average of −0.058R. By market, the average trade was GBP/USD +0.002R, gold −0.040R, AUD/USD −0.056R, EUR/USD −0.062R and silver −0.140R. Silver was the worst: its account lost 67.3% on 1-hour charts and 29.6% on 4-hour charts. Of the 12 tests, 4 made money: USD/JPY on both charts, and EUR/USD (+7.3%) and GBP/USD (+0.5%) on 4-hour charts. EUR/USD and GBP/USD both lost money on 4-hour charts in 2007–2019. Across all 6,083 trades, 33.2% won. The average winning trade made +1.89R and the average losing trade made −1.00R. So a trade needs to win a bit more than 1 time in 3 to break even after costs.

  2. Should you wait for the MACD cross, or enter as soon as the divergence is known? Waiting made about half as many trades: 6,083 compared with 11,107 on 1-hour and 4-hour charts. The win rate was about the same: 33.2% with the wait and 33.0% without. The average trade lost 0.037R with the wait and 0.056R entering at once (see the comparison below). The wait helped on 1-hour charts (−0.041R compared with −0.070R). On 1-hour charts, 1 out of 6 tests made money with the wait, and 0 out of 6 entering at once. It did not help on 4-hour charts (−0.019R with the wait compared with −0.001R at once). Entering at once, 3 out of 6 tests on 4-hour charts made money in both periods: GBP/USD (+26.8%), USD/JPY (+46.7%) and AUD/USD (+44.4%). With the wait, only 1 did: USD/JPY (+15.9%).

  3. Is MACD divergence better than RSI divergence? RSI is another indicator of how hard price has moved, from 0 to 100. We compared MACD divergence with our RSI divergence test, on the same 5 markets (EUR/USD, GBP/USD, USD/JPY, AUD/USD and gold), on 1-hour and 4-hour charts, for trades opened in 2014–2025. MACD divergence made 3,163 trades, and 32.8% won. The average winning trade made +1.92R and the average trade lost 0.043R. RSI divergence made 4,804 trades, and 35.5% won. The average winning trade made +1.75R and the average trade lost 0.037R. Neither strategy made money on average. MACD did better on 4-hour charts (+0.030R compared with −0.086R) and worse on 1-hour charts (−0.061R compared with −0.024R). The RSI version also closes a trade early when RSI reaches 70 or 30, which is one reason its winning trades were smaller (see the table below).

  4. Bearish divergence sells lost money, and bullish divergence buys made a very small profit. On 1-hour and 4-hour charts, the 2,844 buys won 35.4% of the time and made +0.025R on average. The 3,239 sells won 31.3% and made −0.090R. Stock indices tend to rise over time, which helps buys. But these markets are currency pairs and metals, so that does not explain the gap.

Wait for the MACD cross?

Waiting for the cross made half as many trades. The average trade lost less on 1-hour charts, but more on 4-hour charts

These numbers cover the standard rules (wait for the MACD line to cross the signal line) and the version that enters as soon as the divergence is known, with no wait for the cross. Both ran on 1-hour and 4-hour charts: 12 tests on 6 markets, from 2007 to 2025, after trading costs. R is the result of a trade divided by the amount it risked: 1% of the account when the trade opened.

Average trade, waiting for the cross
−0.037R
of 6,083 trades, 33.2% won. 1-hour charts −0.041R, 4-hour charts −0.019R.
Average trade, entering at once
−0.056R
of 11,107 trades, 33.0% won. 1-hour charts −0.070R, 4-hour charts −0.001R.
1-hour tests that made money, waiting for the cross
1 out of 6
from 2007 to 2025
1-hour tests that made money, entering at once
0 out of 6
from 2007 to 2025
4-hour tests that made money in both periods, waiting
1 out of 6
USD/JPY, +15.9%
4-hour tests that made money in both periods, entering at once
3 out of 6
GBP/USD, USD/JPY and AUD/USD

Both periods means both 2007–2019 and 2020–2025. Entering at once opens the trade when the confirmation candle closes, without waiting for the MACD cross, so it makes more trades from the same divergences. With the wait, USD/JPY was the only market that made money in both periods, on both the 1-hour and 4-hour charts. R figures are the average of each trade's result divided by the amount it risked (1% of the account when the trade opened).

MACD divergence compared with RSI divergence

Neither divergence strategy made money on average: MACD did better on 4-hour charts and worse on 1-hour charts

Both strategies ran on the same 5 markets (EUR/USD, GBP/USD, USD/JPY, AUD/USD and gold), on 1-hour and 4-hour charts, for trades opened in 2014–2025, with trading costs and 1% risk per trade. Our RSI divergence page tests the RSI version. R is the result of a trade divided by the amount it risked: 1% of the account when the trade opened.

1-hour and 4-hour charts MACD divergence RSI divergence
Trades 3,163 4,804
Win rate 32.8% 35.5%
Average winning trade +1.92R +1.75R
Average trade, winners and losers together −0.043R −0.037R
Average trade, 1-hour charts −0.061R −0.024R
Average trade, 4-hour charts +0.030R −0.086R

The RSI version also closes a trade early when RSI reaches 70 (for a buy) or 30 (for a sell), which is one reason its winning trades were smaller. The R figures measure each trade's result against the amount it risked, in the same way for both strategies.

Stock indices

On stock indices, 2 out of 6 tests on 1-hour and 4-hour charts made money

A separate test of the standard rules, from 2019 to 2025, after trading costs, on the Nasdaq 100, the S&P 500 and the DAX (the German stock index). We tested the indices apart from the main 18 tests, because our index prices on charts below daily are reliable only from 2019. 'Won' is the share of trades that made money. 'Return' is how much the $10,000 account grew or shrank in the test. The last two columns show the return in each part of the years.

Test Trades Won Return, 2019–2025 2019–2022 2023–2025
Nasdaq 100, 1-hour 281 34.5% +1.8% −8.2% +10.8%
Nasdaq 100, 4-hour 79 31.6% −6.5% −5.9% −0.7%
Nasdaq 100, daily 16 31.2% −0.1% −5.5% +5.7%
S&P 500, 1-hour 305 29.5% −33.3% −24.4% −11.8%
S&P 500, 4-hour 84 29.8% −9.9% −5.1% −5.0%
S&P 500, daily 22 18.2% −9.3% −5.2% −4.4%
DAX, 1-hour 259 31.3% −15.1% −0.6% −14.6%
DAX, 4-hour 79 36.7% +8.6% +4.1% +4.3%
DAX, daily 10 10.0% −5.8% −3.4% −2.5%

Over the 1-hour and 4-hour tests together, the 1,087 trades won 31.9%, and the average trade lost 0.050R. R is the result of a trade divided by the amount it risked: 1% of the account when the trade opened. Only the 3 tests on 1-hour charts had 100 or more trades, so the 4-hour and daily results are too thin to judge. The DAX prices have zero-volume minutes in them (see the 'DAX data' row in the settings). Without those minutes, the conclusions stay the same.

The strategy

What the MACD divergence strategy is

MACD is an indicator that measures momentum: how fast, and in which direction, price is moving. It has two lines. The MACD line is the gap between two EMAs of the closing price: one over the last 12 candles and one over the last 26. An EMA (exponential moving average) is an average price that gives more weight to recent candles. The signal line is the 9-candle EMA of the MACD line, so it moves more smoothly. A divergence is when price and an indicator point in different directions. In a bullish divergence, price makes a lower low, but MACD makes a higher low: price fell further, but the downward momentum was weaker than before. Many traders read this as a sign that the fall is ending, so they buy when the MACD line crosses above the signal line. A bearish divergence is the opposite: price makes a higher high while MACD makes a lower high, and traders sell short, which means selling first, expecting the price to fall. This page tests both of these, which traders call regular divergence. Hidden divergence is a different setup, and it is not tested here.

MACD
12, 26, 9 (the standard settings), calculated on the close of each candle
Swings
A swing low is a low below the lows of the 3 candles on each side. A swing high is a high above the highs of the 3 candles on each side. The two swings of a divergence are 5 to 60 candles apart.
Zero line
For a buy, the MACD line must be below zero at the second swing low. For a sell, it must be above zero at the second swing high.
Wait for the cross
The trade opens when the MACD line crosses the signal line after the second swing. The test waits up to 20 candles after the confirmation candle. It cancels the wait if a candle closes beyond the second swing (below its low for a buy) first.
Stop-loss
0.25 ATR below the second swing low for a buy, or 0.25 ATR above the second swing high for a sell. ATR(14) is how far price moves in an average candle, over the last 14 candles. The stop-loss does not move.
Take-profit
2 times the distance from the close of the entry candle (the candle that triggers the trade) to the stop-loss. No other exit.
Risk per trade
1% of the account when the trade opens. The account started at $10,000, a CFD account.
Trading costs
The spread: the gap between the buy price and the sell price. On the currency pairs, the spread is 0.8 pips on EUR/USD, 0.9 on USD/JPY, 1.0 on AUD/USD and 1.2 on GBP/USD. A pip is 0.0001, or 0.01 on the pairs with the Japanese yen. The spread is $0.30 an ounce on gold and $0.020 on silver. The silver spread is wider than our backtest engine's own, to match a typical retail broker. In the separate stock index test, the spread is 1.5 points on the Nasdaq 100, 0.4 on the S&P 500 and 1.0 on the DAX. The Nasdaq 100 and DAX spreads are wider than the engine's own. The entry is a market order (an order that fills at the next price), so it pays half the spread. A trade that closes at the stop-loss pays the other half. The take-profit is a limit order (an order that waits at a set price), so it pays no spread. For a buy, it fills as soon as the bid price (the price you can sell at) shown on the chart touches it. No commission.
Overnight (swap) fees
Not included. Brokers charge or pay a fee for each night a trade stays open. The median trade lasted 16.8 hours on 1-hour charts and 59.6 hours on 4-hour charts. On 4-hour charts, 66.3% of the trades stayed open longer than 30 hours, and 23.0% longer than a week. On daily charts, the median trade lasted about 20 days. Results could be higher or lower with a real broker.
EUR/USD data
Our EUR/USD prices for 29 and 30 June 2009 barely move, about 2 pips a day, and then jump 62 pips at midnight. One 1-hour sell trade opened on 30 June with a very small stop-loss. It closed at the take-profit at that midnight jump for +12.9R instead of about 2R. The results on this page include that trade. With the standard rules, the EUR/USD 1-hour test lost 55.2% from 2007 to 2025. Without those two days, it lost 60.1% (2007–2019: −35.6% instead of −28.0%). No other test changes.
DAX data
Our DAX prices have 1,540 minutes with zero volume, mostly late in the evening, between 21:00 and 23:00 German time, on 62 days in 2019–2025. Their prices are 0.5% to 3.5% away from the last real price. The results on this page include them. These prices only affect the separate stock index test (2019–2025). Without them, the DAX 1-hour test lost 18.1% instead of 15.1% (2019–2022: −5.6% instead of −0.6%; 2023–2025: −13.3% instead of −14.6%). The 4-hour test made +13.2% instead of +8.6% (2023–2025: +8.6% instead of +4.3%). The daily test lost 3.8% instead of 5.8%. The conclusions stay the same.
Price data
CFD prices: the prices a broker quotes for a CFD (contract for difference), the product most brokers outside the US offer for trading these markets. The main test starts in 2007, because our silver prices have gaps before that. We tested the stock indices separately, from 2019, because our index prices on charts below daily are reliable only from 2019. We left out Bitcoin and other crypto. Our backtest charges a fixed spread at any price, so the trading costs of a crypto market would be wrong.

The rules we tested

  1. Calculate MACD with the standard settings. The MACD line is the 12-candle EMA of the close minus the 26-candle EMA of the close. The signal line is the 9-candle EMA of the MACD line.
  2. Find the swing lows and swing highs. A swing low is a candle whose low is lower than the lows of the 3 candles before it and the 3 candles after it. A swing high is a candle whose high is higher than the highs of the 3 candles on each side. A swing is only known when the 3rd candle after it closes. We call that the confirmation candle, and the test only uses the swing from then on.
  3. Buy on a bullish divergence. Each time a new swing low is known, compare it with the swing low just before it. We call the earlier one the first swing low and the new one the second swing low. They must be 5 to 60 candles apart. If they are not, there is no divergence. The second swing low must be lower in price than the first. The MACD line at the second swing low must be higher than at the first, and below zero. MACD is read on the two swing low candles themselves.
  4. Sell short on a bearish divergence. This is the opposite of the buy rule: the second swing high is higher in price than the first, the two swing highs are 5 to 60 candles apart, the MACD line at the second swing high is lower than at the first, and it is above zero. If a bullish and a bearish divergence are known on the same candle, there is no trade.
  5. Enter when the MACD line crosses above the signal line (for a buy) after the second swing low. If that cross already happened between the second swing low and the confirmation candle, and the MACD line is still above the signal line, buy when the confirmation candle closes. Otherwise, wait up to 20 candles after the confirmation candle for the cross. Cancel the wait if a candle closes below the second swing low first, or if the 20 candles pass. A newer divergence replaces a waiting one. For a sell, do the opposite. We call the candle that triggers the trade the entry candle. The order is a market order at the close of the signal candle, so it fills at the next candle's open.
  6. ATR is an indicator of how far price moves in an average candle, measured over the last 14 candles. Put the stop-loss 0.25 ATR below the second swing low for a buy, or 0.25 ATR above the second swing high for a sell. The stop-loss does not move.
  7. Take profit at 2 times the distance from the entry candle's close to the stop-loss, measured from that close. There is no other exit: the trade ends at the stop-loss or at the take-profit.
  8. Only one trade is open at a time. A divergence that forms while a trade is open is ignored, and a setup that is still waiting for its cross when a trade opens is dropped.
  9. Size every trade so that, if the stop-loss is hit, the trade loses 1% of the account.
  10. Skip any candle that opens on Friday at 17:00 New York time or later: no signal, entry or exit happens on it. This affects only a few silver candles.

The method

How we tested it

The test

Markets
EUR/USD, GBP/USD, USD/JPY, AUD/USD, Gold and Silver
Charts
1-hour, 4-hour and daily candles
Dates
January 2007 to December 2025
Account
$10,000, risking 1% of the account on each trade
Trading costs
Included. Every trade pays that market's normal trading cost: the spread, which is the gap between the buy price and the sell price.

How a test passes

We call a test passed only if it meets all four checks. A strategy can make money in one backtest and still fail one of these checks.

  • At least 100 trades. With fewer trades, a good result could be luck.
  • It made money from 2007 to 2019 and again from 2020 to 2025. This shows whether the strategy kept working in the newer years, not only in the older ones.
  • A profit factor (the money won divided by the money lost) of at least 1.2 from 2020 to 2025, after trading costs.
  • In 95% of 1,000 random shuffles of the trades, the account must not fall more than 30% from its highest point.

Improvements

Can the MACD divergence strategy be improved?

We tried four changes traders often make to MACD divergence, one at a time. Each ran on 18 tests: the 6 markets, each on 1-hour, 4-hour and daily charts. The counts below include the 6 daily tests, so they are out of 18, not 12. The first enters as soon as the divergence is known, without waiting for the MACD cross. The second drops the zero-line rule. The third removes the take-profit and closes the trade when MACD crosses back. The fourth only trades in the direction of the 200 EMA. If you pick the best change and judge it on the same years you used to pick it, it will almost always look good. So we picked the best change using 2007–2019 only, by the number of tests that made money, and then checked it on 2020–2025.

Version Made money 2007–2019years used to pick the best version Made money 2020–2025years not used to pick it Made money in both periods Passed all four checks
Standard rules The rules under 'The rules we tested', with nothing changed. 6 of 18middle test −4.8% 7 of 18middle test −1.9% 2 0
Enter as soon as the divergence is known Do not wait for the MACD line to cross the signal line. Open the trade when the confirmation candle closes, as soon as the divergence is known. The stop-loss and the take-profit work in the same way as in the standard rules. 8 of 18middle test −6.6% 6 of 18middle test −6.6% 3 0
MACD may be on either side of zero Drop the zero-line rule. The MACD line at the second swing may be above or below zero, for buys and for sells. The other rules stay the same. 7 of 18middle test −6.5% 8 of 18middle test −1.6% 3 0
No take-profit: close when MACD crosses back Remove the 2 times take-profit. A buy closes when the MACD line crosses back below the signal line, and a sell closes when it crosses back above. The trade closes at the candle's close, so the order fills at the next candle's open. The stop-loss stays. 7 of 18middle test −4.3% 8 of 18middle test −1.0% 2 1
Only trade with the 200 EMA trendBest on 2007–2019 Only buy when the entry candle closes above the 200 EMA, an average of the closing price over the last 200 candles that gives more weight to recent candles. Only sell short when it closes below the 200 EMA. The other rules stay the same. 9 of 18middle test 0.0% 9 of 18middle test +0.1% 0 0

No change clearly helped. The 200 EMA trend filter did best in 2007–2019, the years we used to pick the best change. 9 out of 18 tests made money with it, compared with 6 with the standard rules. Entering as soon as the divergence is known made money in 8 tests, dropping the zero-line rule in 7, and closing when MACD crosses back in 7. In 2020–2025, the years we kept for the check, 9 out of 18 tests made money with the trend filter, compared with 7 with the standard rules. But the filter cut the number of trades by about 3 in 4: 1,428 trades on 1-hour and 4-hour charts, compared with 6,083. On 4-hour charts, it left only 35 to 53 trades per market in 19 years, about 2 to 3 a year, and on daily charts only 4 to 8. So only the 1-hour tests had 100 or more trades, and none of them made money in both periods. The 266 trades on 4-hour charts made +0.159R on average, compared with −0.019R with the standard rules. That is higher, but 266 trades over 6 markets are too few to judge. On 1-hour charts, the average trade was −0.030R, compared with −0.041R. Over 2007–2025, 10 out of 18 tests made money with the trend filter, compared with 8 out of 18 with the standard rules. This count includes tests with fewer than 100 trades. With 100 or more trades, 2 tests made money in both periods with the standard rules (USD/JPY on 1-hour and 4-hour charts). Entering at once made 3 (GBP/USD, USD/JPY and AUD/USD on 4-hour charts). Dropping the zero-line rule made 3, closing when MACD crosses back made 2, and the trend filter made none. Closing when MACD crosses back made smaller winning trades (+1.28R on average, compared with +1.89R) and smaller losing trades (−0.67R, compared with −1.00R). The average trade was −0.031R, compared with −0.037R. Dropping the zero-line rule added few trades (6,530 compared with 6,083) and the average trade was −0.046R, a little worse.

Questions

Questions traders ask

Does MACD divergence work?

Mostly no. In our backtest from 2007 to 2025, with trading costs, the standard rules made money in 4 out of 12 tests (6 markets, each on 1-hour and 4-hour charts). Only USD/JPY made money in both 2007–2019 and 2020–2025, on both charts: +66.2% on 1-hour charts and +15.9% on 4-hour charts. The average trade lost 0.037R, and about 1 trade in 3 won (33.2%). The average winning trade made +1.89R and the average losing trade made −1.00R. So a trade needs to win a bit more than 1 time in 3 to break even after costs. Daily charts gave too few trades to judge.

What is the best timeframe for MACD divergence?

In our test, 4-hour charts did a little better than 1-hour charts, but neither made money on average. The average trade lost 0.019R on 4-hour charts and 0.041R on 1-hour charts. 3 out of 6 tests on 4-hour charts made money over 2007–2025, compared with 1 out of 6 on 1-hour charts. Daily charts gave too few trades to judge: 191 trades in total across 6 markets in 19 years. Their average trade made +0.036R, but with so few trades, that could be luck.

Should you wait for the MACD crossover after a divergence?

It helped a little on 1-hour charts, but not on 4-hour charts. Waiting for the MACD cross cut the number of trades almost in half: 6,083 compared with 11,107 on 1-hour and 4-hour charts. The win rate was about the same (33.2% compared with 33.0%). The average trade lost 0.037R with the wait and 0.056R entering at once. On 1-hour charts, the wait gave −0.041R compared with −0.070R. On 4-hour charts, it gave −0.019R compared with −0.001R, and entering at once made money in more tests in both periods: 3 out of 6, compared with 1.

Is MACD divergence better than RSI divergence?

Not in our test. Neither strategy made money on average. On the same 5 markets, on 1-hour and 4-hour charts, for trades opened in 2014–2025, MACD divergence made 3,163 trades and 32.8% of them won. The average trade lost 0.043R. RSI divergence made 4,804 trades, and 35.5% won. Its average trade lost 0.037R. MACD divergence did better on 4-hour charts (+0.030R compared with −0.086R) and worse on 1-hour charts (−0.061R compared with −0.024R). RSI divergence also closes a trade early at RSI 70 or 30, which is one reason its winning trades were smaller.

Keep exploring

Related strategies we tested

MACD MACD + 200 EMA strategy backtest Made money in 8 of 40 tests, 5 of them in both periods. Best: Gold, 1-hour, +30% MACD MACD crossover strategy backtest Made money in 6 of 21 tests, 4 of them in both periods. Best: DAX, 1-hour, +294% RSI RSI divergence strategy backtest Made money in 5 of 24 tests, 2 of them in both periods. Best: DAX, 1-hour, +49%
The strategy code we ran

This is the exact code from the BacktestingMax strategy engine. Paste it into the strategy editor in the app to run it on any market.

class MacdDivergence(Strategy):
    """Regular MACD divergence, as most traders learn it, plus four changes traders make.
    MACD is the usual 12/26/9 on the close: the MACD line is the 12-candle EMA minus the
    26-candle EMA, and the signal line is the 9-candle EMA of the MACD line.
    Pivots. A pivot low is a candle whose low is below the lows of the 3 candles before it and
    the 3 candles after it, so it is only known 3 candles later, when the 3rd candle after it
    closes (the confirmation candle). A pivot high is the mirror image. The MACD value of a
    pivot is the MACD line on the pivot candle itself.
    Standard (all switches off):
      Bullish divergence: a new pivot low is lower than the pivot low before it, but the MACD
      line at the new pivot is higher than at the earlier one, and below zero. The two pivots
      are 5 to 60 candles apart.
      Bearish divergence: the mirror image with pivot highs (a higher high in price, a lower
      MACD high, MACD above zero).
      If a bullish and a bearish divergence confirm on the same candle there is no signal.
      Then wait for the MACD line to cross above its signal line (below it, for a sell) after
      the second pivot. The first such cross counts. If it already happened before the
      confirmation candle closed (the pivot candle itself does not count, the candle after it
      is the first that can) and MACD is still above the signal line on the confirmation
      candle, buy at once at that close. If MACD crossed up and back down since the pivot,
      wait for the next cross up. If MACD was already above the signal line at the pivot and
      never crossed down, wait for a new cross up.
      Wait at most 20 candles after the confirmation candle. The setup is cancelled if a candle
      closes below the second pivot low (above the second pivot high for a sell) before the
      cross, or when the wait runs out. A newer divergence replaces a waiting setup.
      Orders are market orders at the close, so they fill at the next candle's open.
      The stop-loss goes 0.25 ATR(14) beyond the second pivot (below its low for a buy, above
      its high for a sell), using the ATR on the confirmation candle. It never moves.
      Take profit at 2 times the risk (2R), measured from the close of the entry candle.
      Size so the stop costs 1% of the account. One trade at a time: a divergence that forms
      while a trade is open is ignored, and a waiting setup is dropped when a trade is open.
    Skipped candles: a candle that opens on a Friday at 17:00 New York time or later. The
    markets in this test are closed then, but some data has a few minutes of prices after the
    close, which make a tiny extra candle. No signal, entry or exit is taken on it. (The
    pivots and the MACD still follow the real prices.) On a market that trades at the weekend,
    remove this.
    The changes, one at a time:
      no_cross   = 1  no signal-line wait: buy (or sell) at the close of the confirmation
                      candle as soon as the divergence is known
      any_side   = 1  drop the zero-line rule: the MACD at the second pivot may be on either
                      side of zero
      cross_exit = 1  no 2R take-profit: close the trade at the close when the MACD line
                      crosses back below its signal line (buys) or above it (sells). The
                      stop-loss still applies
      trend      = 1  only buy when the entry candle closes above its 200-candle EMA, only
                      sell when it closes below it
    """
    params = {"fast": Param(type=int, default=12, min=2, max=100),
              "slow": Param(type=int, default=26, min=3, max=200),
              "signal": Param(type=int, default=9, min=2, max=100),
              "pivot_bars": Param(type=int, default=3, min=1, max=10),
              "min_gap": Param(type=int, default=5, min=1, max=100),
              "max_gap": Param(type=int, default=60, min=2, max=200),
              "stop_atr": Param(type=float, default=0.25, min=0.0, max=3.0),
              "target_r": Param(type=float, default=2.0, min=0.5, max=10.0),
              "wait_bars": Param(type=int, default=20, min=1, max=100),
              "ema_period": Param(type=int, default=200, min=2, max=500),
              "no_cross": Param(type=int, default=0, min=0, max=1),
              "any_side": Param(type=int, default=0, min=0, max=1),
              "cross_exit": Param(type=int, default=0, min=0, max=1),
              "trend": Param(type=int, default=0, min=0, max=1)}
    lookback = 100
    def init(self, ctx):
        p = ctx.params
        n = p.pivot_bars
        self.macd = ctx.indicator("builtin:macd", fast=p.fast, slow=p.slow, signal=p.signal)
        self.atr = ctx.atr(period=14)
        self.ema = ctx.ema(source=ctx.close, period=p.ema_period)
        self.pl = ctx.pivot_low(source=ctx.low, left=n, right=n)
        self.ph = ctx.pivot_high(source=ctx.high, left=n, right=n)
        self.ny = ctx.clock("America/New_York")
        self.last_low = None   # (bar index, price, MACD) of the latest pivot low
        self.last_high = None  # the same for pivot highs
        self.setup = None      # (side, second pivot price, stop, last bar to enter)
    def divergence(self, ctx, pivot_price, prev, side):
        """A new pivot (confirmed on this candle) against the pivot before it. True for a divergence."""
        p = ctx.params
        n = p.pivot_bars
        m_new = self.macd.macd[n]
        if prev is None or m_new is None or prev[2] is None:
            return False
        gap = (ctx.bar_index - n) - prev[0]
        if gap < p.min_gap or gap > p.max_gap:
            return False
        if side > 0:
            return pivot_price < prev[1] and m_new > prev[2] and (p.any_side == 1 or m_new < 0)
        return pivot_price > prev[1] and m_new < prev[2] and (p.any_side == 1 or m_new > 0)
    def crossed(self, side, k):
        """MACD crossed its signal line in the direction of the trade on the candle k candles back."""
        m, s = self.macd.macd, self.macd.signal
        a, b, c, d = m[k], s[k], m[k + 1], s[k + 1]
        if a is None or b is None or c is None or d is None:
            return False
        return (c <= d and a > b) if side > 0 else (c >= d and a < b)
    def enter(self, ctx, side, stop, tag):
        p = ctx.params
        entry = ctx.close[0]
        e = self.ema.value
        hold = p.cross_exit == 1  # no fixed take-profit: the MACD cross or the stop ends the trade
        if side > 0:
            if not ctx.gate("stop_below_entry", stop < entry):
                return
            if not ctx.gate("above_ema", p.trend == 0 or (e is not None and entry > e)):
                return
            ctx.buy(size=ctx.size_by_risk_pct(0.01, stop=stop, entry=entry), sl=stop,
                    tp=None if hold else entry + p.target_r * (entry - stop), tag=tag)
        else:
            if not ctx.gate("stop_above_entry", stop > entry):
                return
            if not ctx.gate("below_ema", p.trend == 0 or (e is not None and entry < e)):
                return
            ctx.sell(size=ctx.size_by_risk_pct(0.01, stop=stop, entry=entry), sl=stop,
                     tp=None if hold else entry - p.target_r * (stop - entry), tag=tag)
    def on_bar(self, ctx):
        p = ctx.params
        n = p.pivot_bars
        i = ctx.bar_index
        # Read the pivots on every candle, before any return, so no pivot is missed.
        low_price, high_price = self.pl.value, self.ph.value
        bull = bear = False
        if low_price is not None:
            bull = self.divergence(ctx, low_price, self.last_low, 1)
            self.last_low = (i - n, low_price, self.macd.macd[n])
        if high_price is not None:
            bear = self.divergence(ctx, high_price, self.last_high, -1)
            self.last_high = (i - n, high_price, self.macd.macd[n])
        # A tiny candle after the Friday close: no signal, entry or exit on it.
        if not ctx.gate("not_friday_after_close", not (self.ny.weekday == 4 and self.ny.hour >= 17)):
            return
        m0, s0, a = self.macd.macd[0], self.macd.signal[0], self.atr.value
        if m0 is None or s0 is None or a is None:
            return
        pos = ctx.position
        if pos is not None:
            self.setup = None
            if p.cross_exit == 1:
                if pos.is_long and self.crossed(-1, 0):
                    ctx.close_position()
                elif pos.is_short and self.crossed(1, 0):
                    ctx.close_position()
            return
        c0 = ctx.close[0]
        # A new divergence on this candle (both sides on one candle: no clear signal).
        if ctx.gate("divergence", bull != bear):
            side = 1 if bull else -1
            if side > 0:
                pivot = low_price
                stop = pivot - p.stop_atr * a
            else:
                pivot = high_price
                stop = pivot + p.stop_atr * a
            self.setup = (side, pivot, stop, i + p.wait_bars)
            if p.no_cross == 1:
                self.setup = None
                self.enter(ctx, side, stop, "bull_div" if side > 0 else "bear_div")
                return
            # Did the cross already happen between the pivot candle and now, and does it still stand?
            above = (m0 > s0) if side > 0 else (m0 < s0)
            if above and any(self.crossed(side, k) for k in range(0, n)):
                self.setup = None
                self.enter(ctx, side, stop, "bull_div" if side > 0 else "bear_div")
            return
        # Waiting for the signal-line cross.
        if self.setup is not None:
            side, pivot, stop, last_bar = self.setup
            if i > last_bar or (side > 0 and c0 < pivot) or (side < 0 and c0 > pivot):
                self.setup = None  # no cross in time, or price closed past the second pivot
            elif ctx.gate("signal_line_cross", self.crossed(side, 0)):
                self.setup = None
                self.enter(ctx, side, stop, "bull_div" if side > 0 else "bear_div")

Your turn

Test the MACD divergence strategy yourself

Change the settings, the market or the stop-loss and see the result in seconds. Ask the BacktestingMax AI: Backtest MACD divergence on USD/JPY, 1-hour chart, from 2007 to 2025: MACD 12, 26, 9, swings of 3 candles on each side 5 to 60 candles apart, bullish divergence with MACD below zero, buy when MACD crosses above its signal line, stop-loss 0.25 ATR beyond the second swing, take-profit at 2 times the distance to the stop-loss, risk 1% per trade.

Try it free in BacktestingMax

Free account. No credit card needed.

See every strategy we tested Browse strategies shared by traders

Backtest on historical data with trading costs, run by BacktestingMax. Past results do not guarantee future results, and nothing here is financial advice. Updated 23 November 2026.