- Strategy
- Buys a bullish pullback to the 20 EMA on the chart timeframe only when the 20 EMA is above the 50 EMA on both H4 and H1, and sells the mirror when both are bearish. 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 MTF Trend Alignment EA trades in the direction that two higher timeframes agree on, and uses a lower timeframe only to time the entry. If the H4 and H1 trends both point up, it waits for an M15 pullback to the 20 EMA and buys when price closes back above it. If they disagree, it stands aside.
The defaults are designed for EURUSD on an M15 chart. Every order has an ATR-based stop and risk-based position sizing.
How it works
On each new chart bar the EA checks:
- Trend on H4 and H1: the 20 EMA compared with the 50 EMA on the last closed bar of each timeframe. Up if 20 > 50, down if 20 < 50.
- Alignment: both timeframes must point the same way.
- Bullish trigger: the last closed chart bar's low touched or went below the chart 20 EMA, it closed above that EMA, and it closed higher than it opened.
- Bearish trigger: the mirror image.
- A trigger in the trend direction of only one timeframe is ignored and the trend states are logged.
- Stop-loss: 1.5 x ATR(14) of the chart timeframe. Target: 2R.
- Higher-timeframe values use closed bars only, so they do not change during the hour.
How to use it
Attach the EA to an M15 (or M30) chart. Multi-timeframe filters are a practical way to avoid trading lower-timeframe noise against the larger trend; the trading sessions lesson is worth reading too, since M15 pullbacks behave very differently in the Asian and London sessions. The default window of 07:00 to 20:00 server time covers the busiest hours for most brokers.
You can change both trend timeframes, for example D1 and H4 with an H1 chart, as long as the chart timeframe stays lower than the middle one.
Settings
| Input | Default | What it changes |
|---|---|---|
| Higher trend timeframe | H4 | First timeframe that must show the trend. |
| Middle trend timeframe | H1 | Second timeframe that must agree. |
| Trend fast / slow EMA | 20 / 50 | EMAs compared on both trend timeframes. |
| Pullback EMA (chart timeframe) | 20 | EMA that price must dip to and reclaim. |
| Stop-loss distance (x ATR) | 1.5 | Stop distance as a multiple of ATR(14) on the chart timeframe. |
| Take-profit (R multiple) | 2.0 | Target as a multiple of the stop distance. |
| Exit on trend conflict | false | If on, closes when the trend timeframes stop agreeing. |
| 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 | 2611014 | Identifies this EA's trades. |
Limitations
- Higher-timeframe trends are judged with EMAs, which lag, so alignment often arrives late.
- Lower-timeframe trades face spreads that are large relative to their stops; the spread filter matters more here.
- Pullback triggers are frequent; the EA takes the first one only because it allows one position at a time.
- The Strategy Tester needs history for all three timeframes; missing data can delay signals.
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.
Use a tester model based on real ticks where possible, since M15 stops are small and spread changes have a larger effect.

