The Intuition

MACD (Moving Average Convergence Divergence) was developed by Gerald Appel in the late 1970s and remains one of the most widely used momentum indicators. It measures the difference between two exponential moving averages (the MACD line) and then smooths that difference with another EMA (the signal line). The cross of the MACD line over its signal line is the trade trigger.

The insight behind MACD: EMA differences capture acceleration in price momentum. When the short-term EMA is pulling away from the long-term EMA (MACD rising), momentum is accelerating — the asset is moving faster than its trend. When the MACD line crosses above its signal line, the recent acceleration is stronger than its short-run average — a confirmation that momentum is building, not just a random fluctuation.

MACD sits between a pure momentum indicator and a trend-following indicator. The EMA construction gives more weight to recent prices (unlike SMA crossovers, which weight all days equally), making MACD more responsive to recent moves. The standard parameters (12, 26, 9) were chosen empirically for daily data and have become a de facto standard — though many practitioners use different settings for different time frames.

Key assumptions: (1) EMA crossovers reliably signal changes in trend direction. (2) The signal line smoothing adds value by filtering noise from the raw MACD line. (3) The 12/26/9 parameters match the momentum persistence of the asset being traded. In practice, these parameters produce shorter holding periods than a 10/50 day SMA crossover — MACD is more of a swing trading indicator.

The strategy's weakness is the same as all crossover approaches: whipsawing in choppy markets. MACD generates many false signals in range-bound conditions. It also lags — being derived from EMAs — which means entries are late in strong trends and exits are late when trends reverse. Practitioners often combine MACD with a trend filter (e.g., only trade in the direction of the 200-day SMA) to reduce false signals.

The Math

Read this as a compact model summary: what the signal sees, what it ignores, and where fragility can creep in.

EMA_fast(t)  = EWM(Close, span=fast)
EMA_slow(t)  = EWM(Close, span=slow)
MACD(t)      = EMA_fast(t) - EMA_slow(t)
Signal_L(t)  = EWM(MACD, span=signal_period)

Signal(t) = +1  if MACD(t) > Signal_L(t)
          = -1  if MACD(t) < Signal_L(t)

Parameters

ParameterTypeDefaultDescription
fast int 12 Fast EMA period
slow int 26 Slow EMA period
signal_period int 9 Signal line EMA period

Source Code

def run(ticker: str, start: str, end: str, **params) -> dict:
    fast = int(params.get("fast", 12))
    slow = int(params.get("slow", 26))
    signal_period = int(params.get("signal_period", 9))
    df = fetch_ohlcv(ticker, start, end)

    ema_fast = df["Close"].ewm(span=fast, adjust=False).mean()
    ema_slow = df["Close"].ewm(span=slow, adjust=False).mean()
    macd_line = ema_fast - ema_slow
    signal_line = macd_line.ewm(span=signal_period, adjust=False).mean()

    pos = pd.Series(0.0, index=df.index)
    pos[macd_line > signal_line] = 1.0
    pos[macd_line < signal_line] = -1.0

    return run_backtest(df, pos, ticker=ticker, start=start, end=end,
                        strategy=METADATA["slug"],
                        params={"fast": fast, "slow": slow, "signal_period": signal_period})

Further Reading

  • Appel, G. (2005). Technical Analysis: Power Tools for Active Investors. FT Press.
  • Murphy, J. (1999). Technical Analysis of the Financial Markets. NYIF.
  • Chan, E. (2013). Algorithmic Trading, Ch. 2. Wiley.

When It Works / When It Fails

Works
  • Building or waning momentum markets with follow-through
  • When EMA divergence has sustained directional follow-through
  • Broad indices during established trending phases
Fails
  • Choppy, oscillating markets generate false crossovers
  • High-noise instruments with no serial autocorrelation
  • Parameters over-fit to a single ticker or period

Regime Fit

Bull / Calm or Normal vol
Best conditions at 1.0 long. EMA divergence signals have the highest predictive value.
Bull / Stressed vol
Scaled to 0.75 long. Signal remains directionally valid with reduced sizing.
Transition / any vol
0.0–0.35. EMA lines oscillate near crossover; false signal rate is highest.
Bear side
Mirrors Bull profile on short scale. Signal is symmetric by construction.

Compared to Alternatives

vs MA Crossover
MACD uses EMA with a signal line smoothing layer; MA Crossover uses raw SMA comparison. MACD is smoother but requires more parameter decisions.
vs RSI
MACD shows direction and velocity of momentum; RSI measures overbought/oversold on a ratio scale. Different use cases despite both being momentum-based.
vs Donchian
MACD is smooth and lag-heavy by design; Donchian is event-driven and faster at extremes. Donchian will generate more round-trips in noisy markets.
Run This Strategy →