Skip to main content

MACD Crossover EA Template for MetaTrader 5

The MACD (Moving Average Convergence Divergence) Crossover is one of the most trusted momentum strategies in trading. This free EA template uses the standard 12/26/9 MACD with signal line crossover detection, ATR-based risk management, and an optional higher-timeframe trend filter. Best for EURUSD, GBPUSD, and XAUUSD on H1 to H4 timeframes. Build it in AlgoStudio without coding and export a production-ready MQL5 Expert Advisor in minutes.

What Is a MACD Crossover Strategy?

The MACD indicator measures the relationship between two exponential moving averages (by default, the 12 EMA and 26 EMA). The difference between these two EMAs forms the MACD line. A 9-period EMA of the MACD line forms the signal line. When the MACD line crosses above the signal line, it indicates that short-term momentum is turning bullish. When it crosses below, momentum is turning bearish.

This is a momentum-based strategy — it detects shifts in the speed and direction of price movement. Unlike pure trend-following strategies that focus on direction alone, the MACD also captures acceleration and deceleration of trends. A MACD crossover often signals a trend change before a simple moving average crossover does, because it measures the convergence and divergence of the underlying EMAs.

Gerald Appel developed the MACD in the late 1970s, and it remains one of the most widely used indicators in trading. Its popularity is justified by its simplicity and effectiveness: the 12/26/9 default settings have been tested across decades of market data on virtually every tradeable instrument.

How This EA Template Works

BUY SIGNAL: MACD line crosses above the signal line (Signal Cross mode) — optionally, price must be above 200 EMA on H4
SELL SIGNAL: MACD line crosses below the signal line (Signal Cross mode) — optionally, price must be below 200 EMA on H4
EXIT: Stop loss at 1.5x ATR(14) or take profit at 2:1 risk-reward ratio

The template uses signal line crossover detection — it enters when the MACD line crosses the signal line. This is the most common and most reliable MACD entry method, providing early momentum signals without the lag of waiting for a zero-line cross.

The optional higher-timeframe trend filter (200 EMA on H4) ensures you only take MACD signals in the direction of the larger trend. This is especially valuable because the MACD generates frequent crossovers during consolidation periods, and the trend filter helps you avoid most of these false signals.

Default Parameters

These defaults use the universally recognized 12/26/9 MACD on H1. All parameters are exported as input variables so you can optimize them in the MT5 Strategy Tester.

ParameterValueType
Fast EMA Period12Indicator
Slow EMA Period26Indicator
Signal Period9Indicator
Stop Loss1.5x ATR(14)ATR-based
Take Profit2:1 R:RRisk-reward
HTF Trend Filter200 EMA on H4 (optional)Filter
Position Sizing1% risk per tradeRisk

How to Build This EA Without Coding

1. Create a new project in AlgoStudio

Sign up for free (no credit card required) and click “New Project”. Name your project “MACD Crossover Strategy” and open the visual builder canvas.

2. Add the MACD indicator block

Drag a MACD indicator block onto the canvas and keep the standard 12/26/9 settings. Connect it to Buy and Sell condition nodes, then add Stop Loss and Take Profit nodes. The MACD uses signal line crossover detection — buy when the MACD line crosses above the signal line, sell when it crosses below.

3. Configure risk management and optional trend filter

Set the stop loss to 1.5x ATR(14), take profit to 2:1 risk-reward, and position sizing to 1% risk per trade. Enable the higher-timeframe trend filter (200 EMA on H4) to trade only in the direction of the larger trend. This prevents most false signals during sideways markets.

4. Export, backtest, and optimize

Click Export to generate a .mq5 file. Load it into MetaTrader 5 and backtest on EURUSD H1 with at least 2 years of historical data. Optimize the MACD periods cautiously — the standard 12/26/9 is hard to beat. Demo trade for 1-3 months before going live.

Optimization Tips

Use the HTF trend filter

Adding a 200 EMA on H4 as a trend filter significantly reduces false signals. Only take buy signals when price is above the EMA and sell signals when below. This prevents most whipsaw losses during consolidation periods and keeps you trading in the direction of the dominant trend.

Consider wider stops for volatile instruments

The default 1.5x ATR stop loss works well for forex pairs. For XAUUSD (gold) and other volatile instruments, increase to 2.0x ATR to avoid being stopped out by normal volatility. The take profit should scale proportionally — if you use 2.0x ATR for the stop, use a 2:1 risk-reward ratio for a 4.0x ATR take profit.

Resist the urge to over-optimize MACD periods

The 12/26/9 MACD has been the standard for over 40 years. If your backtester says 11/23/7 is significantly better, you're likely overfitting. Small changes to MACD periods (like 10/26/9 or 12/28/9) may have merit, but dramatic departures from the standard almost always indicate curve-fitting. A strategy that only works with one specific parameter set is not robust.

Frequently Asked Questions

How does the MACD signal line crossover work?
Signal line crossover enters when the MACD line crosses the signal line — this is the most common and earliest MACD signal. When the MACD line crosses above the signal line, it indicates bullish momentum. When it crosses below, it indicates bearish momentum. This is the standard approach used by most professional traders.
Should I use the standard 12/26/9 MACD settings?
The 12/26/9 settings are the most widely used and most thoroughly backtested. They provide a good balance between signal frequency and quality on H1 and H4 charts. Some traders use 8/17/9 for faster signals or 24/52/18 for slower, more filtered signals. The standard settings are a solid starting point — only change them after extensive testing.
What timeframe works best for MACD Crossover trading?
H1 and H4 are the sweet spot. H1 provides enough signals for active traders while filtering most noise. H4 gives fewer but higher-quality momentum signals. Avoid M5 and M15 where the MACD produces too many false crossovers. D1 works for swing trading but generates very few signals per month.
Can I use MACD Crossover on gold (XAUUSD)?
Yes, XAUUSD is actually one of the best instruments for MACD because gold trends strongly and has clear momentum shifts. Use H1 or H4 timeframes with the standard 12/26/9 settings. Set a wider ATR multiplier (2.0x instead of 1.5x) because gold has higher volatility than forex pairs. Always account for gold's wider spreads in your backtesting.
What win rate should I expect from a MACD Crossover EA?
Expect 35-45% win rate with a 2:1 risk-reward ratio, similar to other momentum strategies. The MACD is a lagging indicator, so it catches trends late and gives back some profit before signaling an exit. The edge comes from riding large winning trades that significantly outsize the frequent small losses. A profit factor above 1.3 is a good target.

Build the MACD Crossover EA in minutes

Create this strategy with AlgoStudio's visual builder. Free plan available — no credit card required.

Start Validating — Free

Risk Warning: Trading in financial markets involves substantial risk of loss and is not suitable for every investor. Past performance does not guarantee future results. Always test strategies on a demo account first. AlgoStudio is a strategy validation platform — it does not provide financial advice or guarantee profits. See our Terms of Service for full details.