Skip to content

Free MT5 Expert Advisor

MTF Trend Alignment EA

MT5 Expert Advisor that enters pullbacks on M15 only when the H4 and H1 EMA trends agree, with an ATR stop-loss and R target.

Multi-timeframev1.0MetaTrader 5 (MQL5) Compiles with 0 errors Non-repainting signals Stop-loss on every trade
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

InputDefaultWhat it changes
Higher trend timeframeH4First timeframe that must show the trend.
Middle trend timeframeH1Second timeframe that must agree.
Trend fast / slow EMA20 / 50EMAs compared on both trend timeframes.
Pullback EMA (chart timeframe)20EMA that price must dip to and reclaim.
Stop-loss distance (x ATR)1.5Stop distance as a multiple of ATR(14) on the chart timeframe.
Take-profit (R multiple)2.0Target as a multiple of the stop distance.
Exit on trend conflictfalseIf on, closes when the trend timeframes stop agreeing.
Risk per trade (% of balance)1.0Share of balance risked between entry and stop.
Fixed lots0Fixed volume instead of risk %; 0 = risk-based.
Maximum spread (points)20Skips signals when the spread is wider; 0 = off.
Trading start / end hour7 / 20Server-time window for new trades; equal values = 24 hours.
Move stop to break-eventrueStop to entry + 20 points once profit reaches 1R.
Use trailing stopfalseTrails the stop 2 x ATR behind price.
Magic number2611014Identifies 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.

Key inputs

Key inputs of MTF Trend Alignment EA
InputDefaultDescription
Higher trend timeframeH4First timeframe that must show the trend.
Middle trend timeframeH1Second timeframe that must agree.
Trend fast / slow EMA20 / 50EMAs compared on both trend timeframes.
Pullback EMA (chart timeframe)20EMA that price must dip to and reclaim.
Stop-loss distance (x ATR)1.5Stop distance as a multiple of ATR(14) on the chart timeframe.
Take-profit (R multiple)2.0Target as a multiple of the stop distance.
Exit on trend conflictfalseIf on, closes when the trend timeframes stop agreeing.

Educational tools, not advice. Automated trading can lose money quickly. Indicators and Expert Advisors describe price; they do not predict it, and past behaviour does not guarantee future results. Test everything on a demo account first and never risk money you cannot afford to lose. See our disclaimer.

Keep exploring

Related mt5 expert advisors