- Strategy
- Buys when the 20 EMA crosses above the 50 EMA on a closed bar while price closes above the 200 EMA, and sells the mirror image. The stop is 1.5 x ATR and the target is 2R.
- Risk model
- 1% of balance per trade (configurable), stop-loss on every order, one position at a time
What it does
The EMA Crossover Trend EA automates one of the oldest trend-following ideas: buy when a fast exponential moving average crosses above a slower one, sell when it crosses below. To avoid trading every wiggle against the bigger picture, it only accepts crossovers that agree with a long 200-period EMA.
Every trade is opened with a volatility-based stop-loss and an optional fixed reward-to-risk target, and the position size is worked out from the stop distance so each trade risks a set percentage of your balance.
How it works
All signals are evaluated once per bar, on the bar that has just closed, so nothing changes while a candle is still forming.
- Bullish cross: the fast EMA was at or below the slow EMA two bars ago and is above it on the last closed bar.
- Trend filter: a bullish cross is traded only if that bar closed above the 200 EMA (a bearish cross only if it closed below). Rejected crosses are written to the Experts log with the reason.
- Stop-loss: entry price minus 1.5 x ATR(14) for buys, plus 1.5 x ATR for sells.
- Take-profit: entry plus 2 x the stop distance (2R). Set it to 0 to rely on the exit cross instead.
- Exit cross: with the default setting, an open buy is closed when the fast EMA crosses back below the slow EMA, whether or not the trend filter agrees.
- Size: lots = (balance x risk %) ÷ (stop distance ÷ tick size x tick value), rounded down to the volume step.
How to use it
This EA suits liquid pairs that trend for days at a time, such as EURUSD or GBPUSD on H1 and H4. Read the 200 EMA as the "permission" layer and the crossover as the trigger.
If you are new to the building blocks, the lessons on moving averages and the risk-reward ratio explain why the stop and target are expressed in R.
Settings
| Input | Default | What it changes |
|---|---|---|
| Fast EMA period | 20 | Faster moving average used for the crossover. |
| Slow EMA period | 50 | Slower moving average used for the crossover. |
| Trend filter EMA period | 200 | Crossovers are taken only on the matching side of this EMA. |
| Stop-loss distance (x ATR) | 1.5 | Stop distance as a multiple of the 14-period ATR. |
| Take-profit (R multiple) | 2.0 | Target as a multiple of the stop distance; 0 disables it. |
| Exit on opposite cross | true | Closes the position on the opposite EMA cross. |
| Risk per trade (% of balance) | 1.0 | Share of balance risked between entry and stop. |
| Fixed lots | 0 | Fixed volume instead of risk %; 0 = risk-based. |
| Maximum spread (points) | 20 | Skips signals when the spread is wider; 0 = off. |
| Trading start / end hour | 7 / 20 | Server-time window for new trades; equal values = 24 hours. |
| Move stop to break-even | true | Stop to entry + 20 points once profit reaches 1R. |
| Use trailing stop | false | Trails the stop 2 x ATR behind price. |
| Magic number | 2611001 | Identifies this EA's trades. |
Limitations
- Crossovers lag: by the time two EMAs cross, a good part of the move may already be over.
- In sideways markets the EMAs cross back and forth and the EA will take a series of small losses.
- The 200 EMA filter reduces counter-trend trades but also skips the start of new trends.
- ATR stops widen in volatile conditions, which shrinks the position size; very quiet markets can produce stops close to the broker's minimum distance.
Before you run it live
Test on a demo account and in the MetaTrader 5 Strategy Tester over several years first. No backtest results are published for this EA, and any test describes the past only.
- Match the spread limit and trading hours to your broker's spreads, stop level and session times, and include commission and swap in tests.
- Start with 1% risk or less and check the lot sizes in the Experts log; the Position Size Calculator is a useful cross-check.
- Use a different magic number on each chart, and keep the terminal (or a VPS) running so stops are managed.
Pay particular attention to how many crossovers the Strategy Tester shows in ranging months; that is where this design is weakest.

