MACD Indicator Deep Dive

Understand MACD line, signal line, histogram, and how to read crossover and divergence signals.

What is MACD?

MACD (Moving Average Convergence Divergence) is a trend-following momentum indicator created by Gerald Appel in the 1970s. It shows the relationship between two exponential moving averages and is one of the most popular indicators in trading — used by beginners and professionals alike.

MACD works by measuring how two moving averages are converging (coming together) or diverging (moving apart), which reveals changes in trend strength, direction, and momentum.

MACD Components

MACD consists of three visual elements:

  • MACD Line — The difference between the 12-period EMA and the 26-period EMA. When this line is positive, the short-term trend is above the long-term trend (bullish). When negative, it is bearish.
  • Signal Line — A 9-period EMA of the MACD line. It acts as a smoothed trigger for buy/sell signals.
  • Histogram — The difference between the MACD line and the signal line, displayed as bars. Positive bars mean MACD is above the signal (bullish momentum); negative bars mean it is below (bearish momentum).
MACD Line   = EMA(12) - EMA(26)
Signal Line = EMA(9) of MACD Line
Histogram   = MACD Line - Signal Line

MACD Trading Signals

Signal Line Crossover (most common):

  • Bullish: MACD line crosses above the signal line — momentum is shifting upward
  • Bearish: MACD line crosses below the signal line — momentum is shifting downward

Centerline Crossover:

  • Bullish: MACD line crosses above zero — the 12 EMA is now above the 26 EMA, confirming an uptrend
  • Bearish: MACD line crosses below zero — the 12 EMA is below the 26 EMA, confirming a downtrend

Histogram Analysis:

Watch the histogram bars for changes in momentum before the lines cross. When histogram bars start shrinking (getting shorter), momentum is fading — a crossover may be coming. This gives you an early warning before the actual signal.

MACD Divergence

Like RSI, MACD divergence is a powerful reversal signal:

Bullish Divergence: Price makes lower lows, but MACD makes higher lows. Selling pressure is decreasing — potential upward reversal.

Bearish Divergence: Price makes higher highs, but MACD makes lower highs. Buying pressure is fading — potential downward reversal.

💡
MACD + RSI Confirmation

A bullish MACD crossover confirmed by RSI moving above 50 is a stronger signal than either alone. Combining a trend indicator (MACD) with a momentum oscillator (RSI) reduces false signals significantly.

MACD Settings

The default settings (12, 26, 9) work well for most instruments and timeframes. Adjustments:

  • Faster settings (8, 17, 9): More sensitive to price changes, generates more signals. Better for short-term trading.
  • Slower settings (19, 39, 9): Smoother, fewer signals but more reliable. Better for position trading.

Common Mistakes

  • Treating every crossover as a trade signal — In ranging markets, MACD generates many false crossovers. Always confirm the market is trending first.
  • Ignoring the histogram — The histogram gives early warnings that many traders miss. Shrinking bars are the first sign of weakening momentum.
  • Using MACD in isolation — MACD is a lagging indicator. Combine it with price action and support/resistance levels for better results.

MACD in MQL5

In MQL5, access MACD through the iMACD() function:

int macdHandle = iMACD(_Symbol, PERIOD_CURRENT, 12, 26, 9, PRICE_CLOSE);
double macdLine[], signalLine[], histogram[];
CopyBuffer(macdHandle, 0, 0, 3, macdLine);    // MACD line
CopyBuffer(macdHandle, 1, 0, 3, signalLine);  // Signal line

Note that MACD buffer index 0 is the MACD line and index 1 is the signal line. The histogram must be calculated manually (macdLine - signalLine) in MQL5.