Oscillators MomentumTrend FollowingCrossover Available in Builder

Moving Average Convergence Divergence (MACD)

MACD

MACD is an unbounded momentum oscillator built from two moving averages. It tracks the gap between a fast and a slow EMA to show when momentum is accelerating, stalling, or turning — and its signal-line and zero-line crossovers make it one of the most direct indicators to turn into a no-code EA.

Default settings
12 / 26 / 9
Signal period
9
Centre
Zero line
Zero lineMAIN_LINE (histogram)SIGNAL_LINE

Illustrative — synthetic data, not a live quote.

What MACD tells you

MACD turns two moving averages into a single momentum reading. It subtracts a slow EMA from a fast one, so the result grows when a move is accelerating and shrinks as it fades — and a second, smoothed line marks the moment that momentum changes hands.

  • Above zero: the fast EMA leads — bullish momentum bias
  • Below zero: the slow EMA leads — bearish momentum bias
  • MT5 draws MAIN_LINE as the histogram — the bars are the MACD line, not MACD minus signal
  1. 1 Fast EMA minus slow EMA → MAIN_LINE
  2. 2 MAIN_LINE smoothed → SIGNAL_LINE
  3. 3 MT5 draws MAIN as bars, SIGNAL as a line
Show the formula & calculation detail

MACD is derived from moving averages of price — the 12, 26, and 9 period settings by default. In MetaTrader 5 the indicator publishes two buffers:

  1. Compute the fast EMA (12 periods) and the slow EMA (26 periods) of the applied price.
  2. Subtract the slow EMA from the fast EMA. This difference is MAIN_LINE (buffer 0): MAIN = EMA(12) − EMA(26). The MT5 terminal draws this buffer as the histogram.
  3. Average MAIN_LINE over the signal period to get SIGNAL_LINE (buffer 1): SIGNAL = MA(MAIN, 9). MT5’s standard MACD uses a simple moving average here; the classic construction uses a 9-period EMA. The terminal draws this buffer as the line over the histogram.

There is no third buffer. MAIN − SIGNAL — the quantity most other charting packages draw as the MACD histogram — is a separate MetaTrader indicator, the Moving Average of Oscillator (OsMA), called with iOsMA. Keeping the two names apart matters in practice: “the histogram flipped sign” means something different on an MT5 chart (MAIN crossed zero) than it does elsewhere (MAIN crossed SIGNAL).

Because it is built from moving averages rather than a bounded ratio, MACD is unbounded. Its values scale with the instrument’s price and volatility, so a reading of 0.0020 on EUR/USD is not comparable to 0.20 on an index. What carries meaning is MAIN_LINE’s position relative to zero and to SIGNAL_LINE, not the absolute number.

In MQL5 the call is iMACD(symbol, period, fast_ema_period, slow_ema_period, signal_period, applied_price). applied_price is a full ENUM_APPLIED_PRICE argument, so the EMAs can be built from Open, High, Low, Median, Typical or Weighted price as well as Close. Gerald Appel developed the original MACD in the late 1970s.

Signals

The distinct, backtestable signals MACD gives — and the regime each one suits.

Signal-Line Crossover

Builder ready
Condition
The MAIN_LINE histogram crosses its SIGNAL_LINE
Best regime
Trending or turning markets
Typical use
Time entries as momentum changes hands

Zero-Line Crossover

Builder ready
Condition
MAIN_LINE crosses above or below zero
Best regime
Established trends
Typical use
Confirm the momentum bias has actually flipped

Divergence

Advanced logic
Condition
Price makes a new extreme, MAIN_LINE does not
Best regime
Trend exhaustion
Typical use
Anticipate a stall before price confirms

OsMA Momentum

Builder ready
Condition
MAIN_LINE minus SIGNAL_LINE — the OsMA indicator — grows or shrinks
Best regime
Either regime
Typical use
Read acceleration before the crossover completes

MT5 implementation

What MetaTrader 5 itself computes and draws — the reference every rule on this page is written against.

Buffers

Index Buffer Drawn in MT5 as What it holds
0 MAIN_LINE Histogram Fast EMA minus slow EMA. This is the buffer the MT5 terminal draws as the histogram — it is the MACD line itself, not a difference from the signal.
1 SIGNAL_LINE Line MAIN_LINE smoothed over the signal period, drawn as the line over the histogram. MT5's standard MACD smooths it with a simple moving average.

Platform notes

Works best / use carefully

No indicator is a universal edge. Here is where MACD helps — and where it misleads.

Works best

  • Trending markets
  • Clear momentum shifts
  • With a trend or volatility filter
  • On higher timeframes

Use carefully

  • Tight, directionless ranges
  • MACD alone as an entry
  • Fast settings on low timeframes
  • Optimised settings without validation

Build a strategy with MACD

Wire the signal into entry and exit rules, then export a compilable MT5 EA — no code.

  1. MACD MAIN (12/26/9)
  2. MACD SIGNAL (12/26/9)
  3. MAIN crosses above SIGNAL → Open Buy · SL 40 / TP 80
  4. MAIN crosses below SIGNAL → Open Sell

Combine MACD with other indicators

One indicator rarely stands alone. These pairings cover MACD's blind spots.

MACD + OsMA

  1. OsMA above zero
  2. OsMA rising against its own value 3 bars back
  3. Buy
Why
OsMA is MAIN minus SIGNAL, so it crosses zero at the same bar the two lines cross — but it also states how far apart they are, which lets a rule ask whether the gap is still widening instead of only whether it has closed
Best regime
Trending

There is no template that places MACD and OsMA in one flow, and there should not be: OsMA is MAIN − SIGNAL, so both together would state the same crossover twice. The OsMA Re-acceleration + Zero Line template shows the OsMA form on its own.

Open Builder →

MACD + RSI

  1. MAIN crosses above SIGNAL
  2. RSI > 50
  3. Buy
Why
Confirm a MACD crossover only when a bounded momentum gauge agrees, filtering the flat-market whipsaws MACD is prone to
Best regime
Trending

No template pairs MACD with RSI. Start from MACD Signal and add an RSI node, a Compare at 50 and an And gate ahead of the Buy action.

Open Builder →

MACD + ADX

  1. ADX > 25
  2. MAIN crosses above SIGNAL
  3. Buy
Why
Take MACD crossovers only when ADX confirms a real trend, since MACD signals inside a dead range are mostly noise
Best regime
Trending

No template pairs MACD with ADX. Start from MACD Signal and add an ADX node with a Compare at 25 — the ADX Trend template shows that filter wired up.

Open Builder →

MACD + Moving Average

  1. Price > 200 MA
  2. MAIN crosses above SIGNAL
  3. Buy
Why
Trade MACD crossovers only in the direction of a higher-timeframe moving average, so you are never fighting the dominant trend
Best regime
Trend continuation

No template pairs MACD with a moving average. Start from MACD Signal and add an MA node plus a Price node into a Compare, gated with And.

Open Builder →

Parameters

Starting values to validate on your own pair and timeframe — not guaranteed settings.

Parameter Default Suggested test range What it does
Fast EMA 12 5–20 The faster moving average. Shorter reacts sooner and fires more crossovers; longer is calmer and slower to turn.
Slow EMA 26 20–40 The slower moving average. The gap between fast and slow is MAIN_LINE itself — widen it for fewer, larger swings.
Signal period 9 5–15 Averaging period applied to MAIN_LINE to produce SIGNAL_LINE. Lower is twitchier; higher lags more but whipsaws less. MT5's standard MACD smooths with a simple moving average, so this is a period, not an EMA length.
Applied price Close Close / Open / High / Low / Median / Typical / Weighted Price series the two EMAs are built from. Close is the MT5 default and the standard choice; iMACD accepts any ENUM_APPLIED_PRICE value, so this is selectable, not fixed.

Starting presets

Standard 12 / 26 / 9 Appel's default baseline
Faster 8 / 17 / 9 Reacts sooner, more whipsaw
Slower 19 / 39 / 9 Fewer, higher-conviction signals

Market examples

Where MACD works, where it fails, and how a filter changes the outcome.

Works

Crossover that caught the trend

As a market began to trend, MAIN_LINE crossed up through SIGNAL_LINE near the zero line and the move followed through — the textbook momentum-entry case.

Fails

Whipsaw in a flat market

In a tight range MAIN_LINE hugs SIGNAL_LINE and crosses back and forth. Trading every cross here churns costs with no move to ride.

Filtered

Filtered by trend strength

Add an ADX or moving-average filter and the same cluster of crossovers is ignored while the market goes nowhere — the filter is what separates a real signal from range noise.

FAQ

What are the best MACD settings for an EA?
12 / 26 / 9 is Gerald Appel's default and the right starting point. Faster settings (for example 8 / 17 / 9) react sooner but whipsaw more; slower ones give fewer, higher-conviction signals. Treat any setting as a baseline to re-validate on your own pair and timeframe in a backtest, not as portable truth.
Is the signal-line cross or the zero-line cross better?
They answer different questions. The signal-line cross times momentum changing hands and fires earlier; the zero-line cross confirms the momentum bias has actually flipped and fires later with fewer false starts. A common EA design uses the zero line as a filter and the signal cross as the trigger.
Why does MACD whipsaw so much in ranges?
Because it is built from moving averages. In a flat market the fast and slow EMAs sit almost on top of each other, so MAIN_LINE crosses SIGNAL_LINE repeatedly with no trend to profit from. Pair it with a trend-strength filter such as ADX, or a higher-timeframe moving average, before trading the crosses.
Where is the MACD histogram in MT5?
The histogram you see on an MT5 chart is MAIN_LINE — the fast EMA minus the slow EMA — drawn as bars, with SIGNAL_LINE as the line over it. iMACD has no third buffer. The MACD-minus-signal histogram used by most other charting packages exists in MT5 as a separate indicator, OsMA (Moving Average of Oscillator), reached with iOsMA. So bars shrinking toward zero on an MT5 MACD means momentum itself is fading, not that the two lines are converging.
Is the MT5 signal line a 9-period EMA?
No. MT5's standard MACD averages MAIN_LINE with a simple moving average over the signal period, while the classic construction uses a 9-period EMA. That is why this page says signal period rather than signal EMA. The two shapes are similar, but crossovers can land a bar apart — enough to matter when comparing an MT5 backtest with a chart drawn in another package.
How should I validate MACD settings before going live?
Backtest on quality tick data first, then run the EA on a demo account before risking money. When optimising, hold back data the search never saw and prefer settings that stay profitable across periods over the single in-sample peak — chasing that peak is overfitting the noise. No default or preset here is a performance promise; every value is a starting point to re-validate on your own pair and broker.