Moving Average Crossover EA Template for MetaTrader 5
The Moving Average crossover is the most popular trend-following strategy in forex trading. This free EA template uses a fast 10 EMA and slow 50 EMA crossover with ATR-based risk management, optimized for the London session. Build it in AlgoStudio without coding, customize the parameters, and export a production-ready MQL5 Expert Advisor in minutes.
What Is a Moving Average Crossover Strategy?
A Moving Average crossover strategy compares two moving averages with different periods. The fast MA (short period, like 10) reacts quickly to recent price changes. The slow MA (longer period, like 50) represents the broader trend. When the fast MA crosses above the slow MA, it signals a potential new uptrend. When it crosses below, it signals a potential downtrend.
This is a trend-following approach — it doesn't try to predict reversals or pick tops and bottoms. Instead, it waits for a trend to establish itself and then rides the move. The trade-off is a lower win rate (35–45%), but winning trades are significantly larger than losing trades because you hold positions through extended trending moves.
The strategy has been used by professional and retail traders for decades because of its simplicity and robustness. It works across all liquid markets and timeframes, making it an ideal starting point for anyone new to automated trading.
How This EA Template Works
The London session filter (08:00–17:00 GMT) ensures you only trade during the most liquid hours, when major forex pairs have the tightest spreads and strongest trends. ATR-based stop losses adapt automatically to current market volatility — wider stops in volatile conditions, tighter stops in calm markets.
The strategy performs best in trending markets with clear directional moves. It underperforms in choppy, sideways conditions where the MAs keep crossing back and forth. Adding an ADX filter (only trade when ADX > 25) is a common improvement to avoid these whipsaw periods.
Default Parameters
These defaults work well on major pairs (EURUSD, GBPUSD) on H1. All parameters are exported as input variables so you can optimize them in the MT5 Strategy Tester.
| Parameter | Value | Type |
|---|---|---|
| Fast MA Period | 10 | EMA |
| Slow MA Period | 50 | EMA |
| Stop Loss | 1.5x ATR(14) | ATR-based |
| Take Profit | 2:1 R:R | Risk-reward |
| Session | London (08:00–17:00 GMT) | Timing |
| Max Trades/Day | 3 | Risk |
| Position Sizing | 1% risk per trade | Risk |
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 “MA Crossover Strategy” and open the visual builder canvas.
2. Add timing and indicator blocks
Drag a Trading Sessions block onto the canvas and select the London session (08:00–17:00 GMT). Add two Moving Average blocks — set one to EMA period 10 (fast) and the other to EMA period 50 (slow). Connect both to the timing block.
3. Add trade execution and risk management
Add Place Buy and Place Sell blocks. Connect Stop Loss (set to 1.5x ATR with period 14), Take Profit (set to 2:1 risk-reward ratio), position sizing (1% risk per trade), and Max Trades Per Day (3). Your entire strategy is now visible on the canvas.
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. Use the MT5 Strategy Tester optimizer to find the best MA periods — try ranges of 5–20 for the fast MA and 30–100 for the slow MA. Demo trade for 1–3 months before going live.
Optimization Tips
Test different MA period combinations
The 10/50 EMA is a strong default, but 8/21, 10/30, and 20/50 are all worth testing. The key is maintaining enough separation between the fast and slow period — if they're too close, you get excessive crossovers and whipsaws.
Add an ADX trend filter
The biggest weakness of MA crossover strategies is choppy, sideways markets. Adding an ADX block with a threshold of 25 ensures you only take trades when a real trend exists. This typically reduces trade count by 30–40% but significantly improves the win rate.
Don't over-optimize
If your backtest shows 90%+ win rates, you've probably overfitted to historical data. A realistic MA crossover wins 35–45% of trades with a positive profit factor. Prefer parameter sets that produce consistent results across multiple years and currency pairs.