Forex
EA

EA: MACD Momentum Expert Advisor

Last updated 2026-07-17

An Expert Advisor (EA) is different from every other download on this site — an indicator only plots or alerts, while an EA actually sends orders on your behalf. 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

Both Stop Loss and Take Profit are sized from ATR rather than a fixed pip distance — a volatile pair or session gets a wider stop automatically, and a calm one gets a tighter stop, so the stop always reflects what the market is actually doing right now rather than an arbitrary number chosen once and left unchanged. 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.

Position size is calculated from RiskPercent (default 1.0%) against your account balance and the Stop Loss distance — the exact worked-example method from Risk Management Basics: risk amount ÷ Stop Loss distance = lot size. 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.
  • ATRPeriod (default 14) — the lookback used to calculate ATR for Stop Loss sizing.
  • ATRMultiplier (default 2.0) — Stop Loss distance = ATR × this multiplier.
  • RiskRewardRatio (default 2.0) — Take Profit distance = Stop Loss distance × this ratio.
  • RiskPercent (default 1.0) — percentage of account balance risked per trade, used to calculate lot size. Ignored if UseFixedLot is enabled.
  • UseFixedLot — switches position sizing from risk-based to a constant lot size.
  • FixedLotSize — the lot size used when UseFixedLot is enabled.
  • MaxSpreadPoints (default 30) — skips new entries while the spread is wider than this, to avoid opening trades at a bad price during illiquid conditions.
  • EnableTrading — a master on/off switch, useful for pausing the EA without removing it from the chart.
  • MagicNumber (default 20260719) — tags every order this EA places so its position-management logic never touches trades opened by hand or by a different EA.

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.

Installation and Setup

EAs install into a different folder than indicators — this is the step people miss most often.

  1. Download the file below for your platform.
  2. Open MetaTrader → click FileOpen Data Folder.
  3. Place the file in MQL4/Experts (MetaTrader 4) or MQL5/Experts (MetaTrader 5) — not the Indicators folder.
  4. Restart MetaTrader, then drag the EA from the Navigator window onto a chart.
  5. Enable AutoTrading (MT4) or Algo Trading (MT5) in the toolbar — the EA will not place any trades while this is off, even if it's attached to a chart.
  6. Review and adjust the input parameters in the EA's settings dialog before confirming.

A Word of Caution

Test on a demo account first, across different market conditions, before risking real money — past performance, in backtests or live, never guarantees future results. 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. Both files are source code — open and review them fully, and understand what every parameter does, before using it. This content is general education, not personalized investment advice.

Download the EA

How to Install — MetaTrader 4

  1. Download the macd-momentum-ea.mq4 file below.
  2. Open MetaTrader 4 → click FileOpen Data Folder.
  3. Place the file in the MQL4/Experts folder.
  4. Restart MetaTrader 4, then drag the EA from the Navigator window onto the chart.

How to Install — MetaTrader 5

  1. Download the macd-momentum-ea.mq5 file below.
  2. Open MetaTrader 5 → click FileOpen Data Folder.
  3. Place the file in the MQL5/Experts folder.
  4. Restart MetaTrader 5, then drag the EA from the Navigator window onto the chart.

Both files are source code — open and review the full code before using it, for your own safety.

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