trend
Trend / Momentum
Intermediate
MACD

MACD

Measures the distance between two EMAs to identify trend direction, momentum shifts, and potential reversals.

Overview

The Moving Average Convergence Divergence (MACD) indicator, developed by Gerald Appel in the late 1970s, converts two exponential moving averages into a momentum oscillator. It shows not just which direction price is trending, but how strongly. The indicator consists of three components: the MACD line, the signal line, and a histogram that visualizes the gap between them.

How it looks on a chart

Illustration only — synthetic data generated for visual reference.

Beginner

MACD works by taking two averages — a fast one (12 days) and a slow one (26 days) — and subtracting the slow from the fast. When the fast average is above the slow average, the MACD line is positive, meaning recent prices are above longer-term prices. This suggests upward momentum. A second line called the "signal line" (a 9-day average of MACD) is plotted alongside. When the MACD line crosses above the signal line, traders interpret it as a buy signal. When it crosses below, it suggests selling. The histogram bar chart shows how wide or narrow this gap is. Divergence is one of the most powerful MACD signals. If price is making new highs but MACD peaks are getting lower, this "bearish divergence" warns that momentum is fading even though price still looks strong. It often precedes a reversal.

Intermediate

The standard parameter set is (12, 26, 9): a 12-period EMA minus a 26-period EMA gives the MACD line, and a 9-period EMA of MACD gives the signal line. The histogram is MACD minus Signal. Histogram bars turning from negative to positive indicate accelerating bullish momentum; bars shrinking from a positive peak signal decelerating momentum. For intraday trading, (5, 13, 6) or (8, 17, 9) are common faster variants. For swing trading on daily charts, (12, 26, 9) remains standard. The zero-line crossing is a slower but more reliable signal than the signal-line crossing — it means the fast EMA has definitively crossed the slow EMA. Combining MACD with RSI improves signal quality: look for MACD signal-line crossovers only when RSI is not yet in overbought/oversold territory, giving more room for the trade to develop. Histogram slope analysis — the rate of change of the histogram — can provide even earlier warning of momentum shifts.

Advanced

MACD is subject to significant whipsaw in low-volatility, ranging markets. One quantitative improvement is to normalize MACD by ATR or price level to make the signal comparable across assets and time periods. Some quant practitioners use MACD as an input feature for machine learning models rather than a standalone signal. The divergence signal, while intuitive, is notoriously difficult to systematize. Academic literature (Brown & Jennings 1989, Blume et al. 1994) shows that momentum indicators derived from moving averages have some predictive validity on weekly horizons but largely disappear after transaction costs on shorter horizons. Look-ahead bias is especially problematic with MACD because the 26-period EMA is calculated recursively from inception — any warm-up period must be discarded. In Gilito's backtests, a minimum of 100 bars of warm-up is enforced before any MACD-based signal is generated to avoid initialization artifacts.

Formula

MACD Line = EMA(12) − EMA(26)
Signal Line = EMA(9) of MACD Line
Histogram = MACD Line − Signal Line
  1. 1.Calculate the 12-period EMA of closing prices.
  2. 2.Calculate the 26-period EMA of closing prices.
  3. 3.Subtract: MACD Line = EMA(12) − EMA(26).
  4. 4.Calculate the 9-period EMA of the MACD Line to get the Signal Line.
  5. 5.Compute Histogram = MACD Line − Signal Line and plot as a bar chart.

Parameters

ParameterDefaultRangeDescription
Fast Period12330Period for the fast EMA component.
Slow Period261060Period for the slow EMA component.
Signal Period9320Period for the signal line EMA.

Trading signals

bullish: MACD line crosses above Signal line

Momentum turning positive — common long entry trigger.

bearish: MACD line crosses below Signal line

Momentum turning negative — common short or exit trigger.

bearish: Bearish divergence: price makes higher high, MACD makes lower high

Hidden weakness — momentum declining even as price advances.

bullish: Bullish divergence: price makes lower low, MACD makes higher low

Hidden strength — selling pressure fading even as price declines.

Limitations

  • Still a lagging indicator derived from moving averages — no predictive power in isolation.
  • Divergence signals can persist for many bars before price actually reverses.
  • Sensitive to parameter choice; optimized parameters often fail out-of-sample.
  • Performs poorly in choppy, sideways markets generating excessive false crossovers.
How Gilito AI uses MACD

Gilito sweeps MACD parameter combinations (fast 6–20, slow 15–50, signal 5–15) in its strategy grid, evaluating each configuration on rolling out-of-sample windows to identify robust settings. It also uses MACD histogram slope as a momentum feature in its composite signal models.

Related indicators