LearnForexHub
EA

EA: MACD Momentum Expert Advisor

Written by , Founder & EditorLast updated How we write and review lessons

An EA is the one kind of download here that acts on its own: indicators describe the market, while an Expert Advisor actually trades it. This free EA trades a single, transparent momentum strategy built entirely around MACD: it enters the moment MACD momentum flips direction, then manages Stop Loss, Take Profit, and position size automatically from the same tools taught elsewhere on this site.

How the Strategy Works

The entry signal is a straightforward MACD line crossing its own signal line — no trend filter, no secondary confirmation, just the crossover itself. As explained in the site's MACD lesson, the MACD line is the difference between a fast EMA (default 12-period) and a slow EMA (default 26-period), and the signal line is a further EMA (default 9-period) of that difference. When the fast EMA is pulling away above the slow EMA, the MACD line rises and eventually crosses above the signal line — a sign that upward momentum has just taken over from downward momentum, or vice versa for a bearish cross. Because the two lines are both derived from price, a crossover is really a statement about acceleration: the crossover happens close to the moment the trend's speed changes, which is exactly why MACD crossovers are used as entry timing rather than just a confirmation tool.

Stop Loss, Take Profit, and Position Sizing

PriceTake Profit (TP)Stop Loss (SL)BUY0MACDMACD lineSignal line
Entry conditions: BUY when the MACD line crosses above the signal line — SELL on the mirrored bearish cross — SL and TP are placed automatically from ATR

Stops and targets here come from ATR, not fixed pips — when the pair moves more, the stop widens; when it quiets down, the stop tightens, tracking current conditions instead of a number set once and forgotten. Stop Loss distance is ATRMultiplier × ATR (default multiplier 2.0), and Take Profit is then set at RiskRewardRatio × Stop Loss distance (default 2.0), so every trade this EA opens carries a fixed, known reward-to-risk proportion regardless of which pair or timeframe it's trading.

Lot size comes from the same arithmetic taught in Risk Management Basics: the account fraction you risk (RiskPercent, default 1.0%) divided by the stop distance. A wider ATR-based stop on a volatile pair automatically produces a smaller lot, and a tighter stop on a calm pair produces a larger lot, so the dollar risk per trade stays roughly constant even though the price distance to the stop changes trade to trade. A UseFixedLot input is available as an escape hatch for traders who'd rather trade a constant lot size regardless of risk percentage — useful for testing or for small accounts where percentage-based sizing rounds to the broker's minimum lot anyway.

Entry Conditions

  • BUY — the MACD line crosses above the signal line (a bullish cross), using the default 12/26/9 EMA settings.
  • SELL — the MACD line crosses below the signal line (a bearish cross) — the mirrored setup.

Beyond the signal itself, three safety mechanics govern every trade: the EA only evaluates these conditions once per new bar (not on every tick, so a single crossover can't fire multiple trades within the same candle), only opens one position at a time (a new signal is ignored while a position from this EA is already open), and only manages positions tagged with its own magic number (20260719) — so it never touches trades you open manually or trades placed by a different EA running on the same account.

Parameters

  • FastEMA (default 12) — the fast EMA period used to calculate the MACD line.
  • SlowEMA (default 26) — the slow EMA period used to calculate the MACD line.
  • SignalPeriod (default 9) — the EMA period applied to the MACD line to produce the signal line that price crosses to trigger entries.

The remaining parameters aren't specific to this strategy: they belong to the risk engine shared across the whole EA collection, explained in one place on the EA hub. This EA identifies its own trades with magic number 20260719.

Why No Trend Filter — And When That's a Feature, Not a Flaw

The site's other EA, the trend-following EA, only acts on a Moving Average crossover after ADX confirms a real trend is underway. This EA deliberately skips that step — it trades every MACD crossover as soon as it happens, with no secondary filter standing between the signal and the order. That's a real design tradeoff, not an oversight. A raw crossover fires more often, which means more opportunities to catch a fresh move right at the start, before a trend filter like ADX would have had time to confirm anything — MACD crossovers tend to lead ADX confirmation rather than follow it, since ADX is built to measure trend strength that has already been established. The cost is that in a choppy, range-bound market, price oscillates back and forth across both EMAs with no real direction, and the MACD line saws across the signal line repeatedly, generating a string of crossovers that reverse again a few bars later — each one technically valid by the entry rule, but collectively a losing pattern once spread and slippage are subtracted from each small, false move. This EA therefore tends to perform best in markets that are trending or breaking out — where being early to a momentum shift pays off — and worst in tight, directionless ranges, where the ADX-filtered trend-following EA would simply sit out and take no trades at all. Neither approach is objectively better: a trader who wants fewer, higher-conviction signals should reach for the trend-following EA, while a trader comfortable managing more trades (and more false signals) in exchange for earlier entries should prefer this one. Checking trend vs range conditions before turning this EA loose on a given pair is the single highest-leverage thing a trader can do to improve its results, even though the EA itself makes no attempt to detect that condition automatically.

A Word of Caution

Before funding it with real money, let it run on demo across several market regimes; no backtest or live record ever guarantees what comes next. No strategy, automated or manual, wins every trade, and this EA can and will lose money on individual trades; trading every MACD crossover with no trend filter means it will take more false signals in choppy markets than a filtered strategy would. The files ship as readable source, so open them in MetaEditor and satisfy yourself about what every parameter does before running them. This lesson exists to explain the mechanics, not to advise you on your own trading decisions.

Download macd-momentum-ea.mq4

For MetaTrader 4 — this is source code (.mq4), open and review it fully before using it.

Download File

Download macd-momentum-ea.mq5

For MetaTrader 5 — this is source code (.mq5), open and review it fully before using it.

Download File

How to install

An EA installs into the Experts folder, not Indicators — this is the step people miss most often.

MetaTrader 4

  1. Download macd-momentum-ea.mq4 above.
  2. Open MetaTrader 4FileOpen Data Folder.
  3. Place the file in the MQL4/Experts folder.
  4. Restart MetaTrader 4, then drag it from the Navigator window onto a chart.
  5. Enable AutoTrading (MT4) or Algo Trading (MT5) in the toolbar — the EA places no trades while this is off, even when attached to a chart.
  6. Review and adjust the input parameters in the settings dialog before confirming.

MetaTrader 5

  1. Download macd-momentum-ea.mq5 above.
  2. Open MetaTrader 5FileOpen Data Folder.
  3. Place the file in the MQL5/Experts folder.
  4. Restart MetaTrader 5, then drag it from the Navigator window onto a chart.
  5. Enable AutoTrading (MT4) or Algo Trading (MT5) in the toolbar — the EA places no trades while this is off, even when attached to a chart.
  6. Review and adjust the input parameters in the settings dialog before confirming.

Both files are source code. Open and read them in MetaEditor before running them on any account.