TL;DR
MACD (Moving Average Convergence Divergence) measures trend momentum by tracking the difference between a 12-period and 26-period EMA. Signal line crossovers and histogram patterns generate buy and sell signals, while MACD divergence warns of potential reversals.
MACD (Moving Average Convergence Divergence) is a trend-following momentum indicator created by Gerald Appel in the late 1970s. It shows the relationship between two exponential moving averages of price and is one of the most popular and trusted indicators in technical analysis. MACD is displayed as two lines and a histogram beneath the price chart. The MACD line represents the difference between the 12-period EMA and the 26-period EMA. The signal line is a 9-period EMA of the MACD line. The histogram plots the difference between the MACD line and the signal line. When the faster EMA (12) is above the slower EMA (26), the MACD line is positive, indicating upward momentum. When the faster EMA is below the slower EMA, the MACD line is negative, indicating downward momentum. This simple concept produces surprisingly reliable trading signals across all markets and timeframes.
MACD consists of three components that work together to provide a comprehensive view of momentum. The MACD line is calculated by subtracting the 26-period EMA from the 12-period EMA. When the 12 EMA is above the 26 EMA, the MACD line is positive, and when below, the MACD line is negative. The signal line is a 9-period EMA of the MACD line, which smooths the MACD and provides a trigger for buy and sell signals. The histogram is the difference between the MACD line and the signal line, providing a visual representation of how quickly the MACD line is moving relative to the signal line. Growing histogram bars indicate increasing momentum, while shrinking bars indicate fading momentum. The histogram crosses zero every time the MACD and signal lines cross each other.
MACD Line = EMA(12) - EMA(26); Signal Line = EMA(9) of MACD Line; Histogram = MACD Line - Signal LineEMA(12) — 12-period Exponential Moving Average of closing price
EMA(26) — 26-period Exponential Moving Average of closing price
Signal Line — 9-period EMA of the MACD line
The most common MACD signal is the crossover between the MACD line and the signal line. A bullish signal occurs when the MACD line crosses above the signal line, indicating that short-term momentum is turning positive relative to the smoothed trend. A bearish signal occurs when the MACD line crosses below the signal line. These crossovers are the MACD equivalent of moving average crossovers but applied to momentum rather than price. The best crossover signals occur when they confirm the direction of the prevailing trend. For example, a bullish MACD crossover during an established uptrend is a high-probability entry signal. Crossovers that occur against the trend are less reliable and often produce false signals. To filter false signals, many traders require that the crossover happens below zero for bullish signals (indicating a recovery from bearish momentum) and above zero for bearish signals (indicating a loss of bullish momentum).
Pro Tip
The most powerful MACD buy signal occurs when the MACD line crosses above the signal line while both lines are below zero. This indicates that bearish momentum is not only fading but reversing, which often coincides with the early stages of a new uptrend.
The MACD histogram is arguably the most useful component of the MACD indicator because it provides the earliest signals. The histogram turns positive when the MACD line crosses above the signal line and negative when it crosses below. More importantly, the histogram's rate of change reveals momentum shifts before the actual crossover occurs. When the histogram is positive but its bars are getting shorter (declining from the peak), it indicates that bullish momentum is fading and a bearish crossover may be approaching. When the histogram is negative but bars are getting less negative (rising from the trough), it indicates that bearish momentum is weakening and a bullish crossover may be coming. This turn in the histogram, from growing to shrinking, is an early warning signal that allows traders to prepare for crossovers before they happen. Some traders use the histogram alone, buying when it turns from negative to positive and selling when it turns from positive to negative.
Like RSI, MACD produces divergence signals when price and the indicator move in opposite directions. Bullish MACD divergence occurs when price makes a lower low but the MACD histogram or MACD line makes a higher low, indicating that downside momentum is weakening despite lower prices. Bearish MACD divergence occurs when price makes a higher high but MACD makes a lower high, suggesting that upside momentum is fading. MACD divergence is particularly effective because it combines two independent measures: price trend and momentum. When these two measures disagree, the momentum measure typically proves correct, as momentum changes precede price changes. The most reliable MACD divergences occur on daily or weekly charts and are confirmed by price action (such as a break of a trendline or support/resistance level). Multiple divergences in the same direction strengthen the signal.
Concrete MACD crossover examples with prices illustrate how to apply the indicator in practice. Scenario 1: Bullish Crossover Below Zero (Strongest Buy Signal). ES futures has been declining, and the MACD line is at -15 with the signal line at -12. Price is at 4,920 near a support level. The MACD line crosses above the signal line while both are below zero. This is the strongest type of bullish crossover because it signals a momentum reversal from bearish to bullish. You enter long at 4,925. Over the next 5 sessions, the MACD line rises toward zero and eventually crosses the zero line, confirming the new uptrend. Price reaches 5,020, a 95-point gain. Scenario 2: Bearish Crossover Above Zero (Strongest Sell Signal). NQ futures is at 18,200 after a strong rally. The MACD line is at +120 and the signal line is at +115. The MACD line crosses below the signal line while both are above zero. This signals fading bullish momentum. You exit longs or enter short at 18,180. Price drops to 17,900 over the next week as the MACD continues falling toward zero. Scenario 3: False Signal in a Range. ES trades between 5,000 and 5,040 for two weeks. MACD oscillates around zero with small crossovers every few days. Each crossover produces only a 10-15 point move before reversing. This is the whipsaw environment where MACD crossovers fail. The solution is to add a minimum MACD distance from zero before acting on crossovers. If you require the MACD line to be at least 5 points from zero before taking a crossover signal, you filter out most range-bound whipsaws.
| Scenario | MACD Position | Signal Strength | Expected Outcome |
|---|---|---|---|
| Bullish cross below zero | Both lines negative, MACD crosses above signal | Very strong | Trend reversal to bullish, large move |
| Bullish cross above zero | Both lines positive, MACD crosses above signal | Moderate | Trend continuation, moderate move |
| Bearish cross above zero | Both lines positive, MACD crosses below signal | Very strong | Trend reversal to bearish, large move |
| Bearish cross below zero | Both lines negative, MACD crosses below signal | Moderate | Trend continuation downward |
| Any cross near zero line | MACD near zero in range | Weak | High probability of false signal |
The default MACD settings (12, 26, 9) work well for most markets and timeframes, but traders can adjust them for different purposes. Shorter settings like (5, 13, 1) make MACD more responsive and suited for day trading, generating more frequent signals. Longer settings like (24, 52, 18) smooth out noise and are better for weekly charts and position trading. When customizing MACD settings, maintain the approximate 2:1 ratio between the slow and fast EMA (e.g., 8/17, 12/26, 24/52) for optimal performance. Some traders also modify the signal line period: a shorter signal line (6 or 7) makes crossovers faster but noisier, while a longer signal line (12 or 14) produces fewer but more reliable crossovers. Whatever settings you choose, be consistent and avoid constantly optimizing to fit recent price action.
NinjaTrader 8 includes MACD as a built-in indicator accessible from the Indicators menu. The NinjaTrader implementation displays the MACD line, signal line, and histogram in a panel below the price chart, with the histogram color-coded (typically green when above zero and red when below). To access MACD values in NinjaScript, use: double macdValue = MACD(12, 26, 9).Default[0] for the MACD line, MACD(12, 26, 9).Avg[0] for the signal line, and MACD(12, 26, 9).Diff[0] for the histogram. A practical NinjaScript crossover strategy can be built with just a few lines: if (CrossAbove(MACD(12,26,9).Default, MACD(12,26,9).Avg, 1) && MACD(12,26,9).Default[0] < 0) EnterLong(). This enters long only when a bullish crossover occurs below the zero line, filtering for the strongest signals. For a more sophisticated approach, combine MACD with ATR for adaptive trade management: enter on a MACD crossover, set the stop at 2x ATR, and trail the stop using the signal line as a reference. Exit when the MACD histogram begins declining from its peak, indicating momentum is fading, rather than waiting for a full bearish crossover. This histogram-based exit captures more profit by exiting during momentum decay rather than after the reversal has already begun. When using MACD on NinjaTrader's Market Analyzer, you can scan multiple instruments simultaneously for crossover signals, creating a watchlist that alerts you when any of your markets generate a MACD signal.
Pro Tip
In NinjaTrader, overlay a MACD histogram with a 3-period SMA of the histogram. When the histogram crosses above its own SMA, it provides an even earlier signal than the standard MACD/signal line crossover, giving you a head start on entries.
Mistake
Taking every MACD crossover signal regardless of trend direction
Correction
Filter crossover signals by trading only in the direction of the higher timeframe trend. Bullish crossovers in uptrends and bearish crossovers in downtrends have significantly higher success rates than counter-trend signals.
Mistake
Ignoring the histogram and only watching for crossovers
Correction
The histogram provides the earliest momentum signals. Declining histogram bars warn of an upcoming crossover, allowing you to prepare and manage existing positions before the signal triggers.