Moving Average Crossover Strategy: Complete Build and Optimization Guide
Build and optimize an MA crossover Expert Advisor step by step. Entry/exit rules, SMA vs EMA, ADX filters, period combinations, and realistic performance expectations.
The Moving Average crossover is the most popular EA strategy in forex trading for a reason: it's simple, it works in trending markets, and it's easy to understand and optimize. It's also the strategy most professional traders started with before building more complex systems. In this guide, we'll build one from scratch, add filters to improve performance, and optimize it properly.
The Basic Concept
A Moving Average crossover uses two MAs with different periods. The fast MA (short period) reacts quickly to recent price changes. The slow MA (long period) smooths out noise and represents the broader trend. When the fast MA crosses above the slow MA, it signals that recent momentum has shifted upward — a potential new uptrend. The opposite cross signals a potential downtrend.
- Fast MA (short period, e.g., 10): Represents recent momentum
- Slow MA (long period, e.g., 50): Represents the broader trend direction
Buy signal: Fast MA crosses above Slow MA (bullish crossover — also called a "golden cross" with 50/200 MA)
Sell signal: Fast MA crosses below Slow MA (bearish crossover — also called a "death cross" with 50/200 MA)
This is a trend-following strategy. 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: lower win rate (35-45%) but larger winners because you hold through extended trending moves.
Choosing Your Moving Averages
SMA vs EMA
The Simple Moving Average (SMA) gives equal weight to all candles in the period. The Exponential Moving Average (EMA) gives more weight to recent candles, making it more responsive to current price action.
| Feature | SMA | EMA |
|---|---|---|
| Responsiveness | Slower | Faster |
| False signals | Fewer | More |
| Signal delay | Later entries | Earlier entries |
| Smoothness | Smoother | More jagged |
| Best for | Daily/weekly charts | H1/H4 charts |
For crossover strategies on intraday timeframes (H1, H4), EMA is generally preferred because it catches trend changes faster. On daily and weekly charts, SMA's smoothness provides higher-quality signals.
Best Period Combinations
- 8/21 EMA: Aggressive short-term crossover. More signals, more noise. Good for scalping on M15-H1.
- 10/50 EMA: Classic short-term crossover. Strong default for H1. This is what we use in our MA Crossover template.
- 20/50 EMA: Balanced approach. Fewer signals but less whipsaw than 10/50.
- 20/100 EMA: Medium-term. Fewer signals but higher quality. Good for H4.
- 50/200 SMA: The "Golden Cross / Death Cross" — long-term trend identification on daily charts. Used by institutional traders.
The key principle: maintain enough separation between the fast and slow periods. If they're too close (like 10/15), you get constant crossovers in any sideways movement. If they're too far apart (like 5/200), signals come too late to be useful.
Building the MA Crossover EA
Here's how to build it in AlgoStudio's visual builder:
- Timing: Drag a Trading Sessions block and select London (08:00-17:00 GMT). This limits trading to the most liquid hours with the tightest spreads.
- Indicators: 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.
- Trade execution: Add Place Buy and Place Sell blocks connected to the indicator conditions.
- Risk management: Add Stop Loss (1.5x ATR with period 14), Take Profit (2:1 risk-reward), Position Sizing (1% risk), and Max Trades Per Day (3).
- Export: Click Export MQL5, compile in MetaEditor, and backtest on EURUSD H1.
Adding Filters to Improve Performance
The raw crossover strategy generates many false signals in ranging markets. Price chops back and forth across both MAs, triggering buy and sell signals in rapid succession. Each one hits the stop loss. This "whipsaw" period is the MA crossover's biggest weakness. Filters reduce this problem dramatically.
ADX Filter (Most Impactful)
The ADX (Average Directional Index) measures trend strength regardless of direction. Adding an ADX block with a threshold of 25 ensures your EA only takes crossover trades when a real trend exists. When ADX is below 25, the market is ranging — and the EA stays out.
This single filter typically reduces trade count by 30-40% while significantly improving the win rate and profit factor. It's the single most effective filter you can add to any trend-following strategy.
RSI Filter
Add an RSI block to avoid buying when the market is already overbought (RSI above 70) or selling when already oversold (RSI below 30). This prevents late entries at the end of strong moves — you don't want to buy a crossover when the pair has already run 200 pips and is due for a pullback.
Session Filter
Limiting trades to the London session or London/NY overlap (13:00-17:00 GMT) ensures you only trade during peak liquidity. Crossovers during the Asian session are more likely to be false breaks because there's less institutional volume to sustain a trend.
Minimum Bar Distance Filter
Add a rule: don't take a new crossover signal if the previous one was fewer than 5 bars ago. Rapid crossovers in choppy markets trigger multiple losing trades. Spacing them out naturally filters whipsaw periods.
Optimization: Finding the Best Parameters
After your basic EA works, use the MT5 Strategy Tester's optimization mode to find better parameters. Here's how to do it without falling into the overfitting trap:
What to Optimize
- Fast MA period: Test range 5-20, step 1
- Slow MA period: Test range 30-100, step 5
- ATR multiplier: Test 1.0, 1.5, 2.0, 2.5
- ADX threshold: Test 20, 25, 30
What NOT to Do
- Don't optimize everything at once — it creates millions of combinations and increases overfitting risk
- Don't pick the single best result — look for parameter plateaus where many nearby values are profitable
- Don't optimize on the full data range — reserve the last 20-30% for out-of-sample validation
- Don't trust any result based on fewer than 100 trades
Expected Performance
A well-optimized MA crossover EA with proper filters typically achieves:
| Metric | Realistic Range | Suspicious If |
|---|---|---|
| Win rate | 35-45% | Above 55% |
| Profit factor | 1.3-1.8 | Above 2.5 |
| Risk-reward ratio | 1:1.5 to 1:3 | Above 1:5 |
| Monthly return | 2-5% | Above 15% |
| Max drawdown | 10-25% | Below 5% |
If your backtest shows 90%+ win rates or 500% annual returns, you've almost certainly overfitted. A realistic MA crossover won't make you rich overnight, but it provides a solid, proven foundation that compounds over time. Many professional traders started with MA crossovers and built more complex strategies on top of this base.
Want to skip the setup? Use our ready-made Moving Average Crossover EA template — pre-configured with 10/50 EMA, ATR-based stops, and London session timing. Or compare this approach with RSI vs MACD strategies.
Related Articles
Ready to build your own EA?
Start building automated trading strategies for MetaTrader 5 — no coding required.
Get Started Free