Metric · Price and risk

MACD Indicator: Formula, Settings and a Worked Example

MACD tracks the gap between a fast and a slow moving average. When the gap widens, momentum is building; when it narrows, momentum is fading, often before price turns.

AI-assisted, reviewed by Lovely Oryza → 4 min read Published

Formula

12-period EMA of price minus 26-period EMA of price; signal line is a 9-period EMA of that difference; histogram is MACD minus signal

MACD (12, 26, 9): A momentum indicator that measures the distance between a fast and a slow exponential moving average of price, and compares that distance with its own recent average.

Also shown as Moving average convergence divergence, MACD line, MACD signal line, MACD histogram.

Two moving averages, one quick and one slow, sit on the same chart. When price rallies, the quick one pulls away from the slow one. When the rally tires, the gap starts closing before either line turns down. MACD is that gap, plotted on its own panel, and the panel beneath many daily charts with a pair of lines and a set of bars is almost always this indicator at its standard settings of 12, 26 and 9.

Three pieces on one panel

The MACD line is the 12-period exponential moving average of price minus the 26-period one. Positive means the fast average is above the slow one. Negative means it’s below.

The signal line is a 9-period exponential average of the MACD line, a smoothed copy that trails behind it, and most of the indicator’s signals come from the moments when the faster MACD line crosses over or under this slower one.

The histogram is the MACD line minus the signal line. Bars above zero mean MACD is above its signal. They grow while momentum accelerates and shrink while it slows.

The exponential average, worked

An exponential moving average puts more weight on recent prices. Each day it moves part of the way toward the latest close. The multiplier is 2 divided by the period plus one.

Look at the sizes. The fast average moved about nine cents, 0.1538 × $0.60. The slow one moved about fourteen, 0.0741 × $1.90, because today’s close sat much further above it, yet it covered only a small share of that distance. That small share is what makes it slow.

Notice the result. Yesterday’s MACD line was 52.40 − 51.10 = 1.30, so it slipped to 1.25 on a day the stock closed higher. The rally continued, the gap between the averages narrowed a little, and the indicator registered that slowing before the price chart showed anything at all.

Crossovers

A bullish crossover is the MACD line rising through the signal line. The histogram flips from negative to positive at the same moment. A bearish crossover is the reverse.

The zero line matters too. MACD crossing above zero means the 12-period average has moved above the 26-period one, which is the same event as a moving-average crossover on the price chart.

Both are late. By the time a crossover prints, price has usually already moved, because two layers of averaging sit between the close and the signal. Crossovers are late by design argues that this is the cost of filtering noise, and not a flaw to fix with faster settings, since faster settings simply trade lateness for more false signals.

Divergence and the histogram

Divergence is price making a new high while MACD makes a lower high. The fast average is still above the slow one, but the gap is shrinking. Momentum is fading under a rising price.

It can last a long time. A stock can show divergence for weeks and keep climbing, so traders who sell on the first sign of it often watch the price go on rising while the indicator keeps printing lower highs underneath.

The histogram shows the same thing sooner. Shrinking bars mean the MACD line is losing ground on its signal, and that often happens several bars before a crossover. Many traders watch the histogram first and treat the crossover as confirmation.

MACD is in dollars

The MACD line is a price difference. A $400 stock produces much bigger MACD readings than a $20 stock with the same percentage trend, so a MACD of 3.0 means nothing until you know the price.

You can’t compare MACD values across stocks, then, and you can’t set one fixed threshold in a screener that would mean the same thing for a $20 stock and a $400 one. Divide by the slow average to fix it. The percentage price oscillator does exactly that: (12-period EMA − 26-period EMA) ÷ 26-period EMA × 100. Same shape, comparable scale.

Where tools differ

  • The starting value. An EMA needs a seed, usually a simple average of the first bars, and different seeds give slightly different readings early in a chart’s history, differences that fade as more bars are added to the calculation.
  • Price input. Closes are standard. Some tools allow typical price or the open.
  • Histogram definition. A few platforms plot MACD minus signal times two, or draw the histogram from the MACD line alone. Read the indicator’s help text.
  • Colors. Some shade bars by direction, some by whether they’re growing.

How to use it

MACD answers one question well: is momentum building or fading? Pair it with something that answers a different one. RSI measures how stretched recent gains are on a fixed 0 to 100 scale, which MACD can’t do. The 50 and 200-day moving averages describe the longer trend that a MACD signal is happening inside. A bullish crossover in a stock below a falling 200-day line is a weaker case than the same crossover above a rising one.

And keep it on the right chart. On a daily chart, 12, 26 and 9 are days. On a weekly chart, the same settings describe months of price action, and the signals arrive far less often. More indicator definitions are in metrics.

Related questions

What do the numbers 12, 26, 9 mean?

They are the periods of the three exponential moving averages: 12 for the fast average of price, 26 for the slow average of price, and 9 for the signal line, which averages the MACD line itself. On a daily chart, each period is one trading day.

Is MACD a leading or lagging indicator?

It is built from moving averages, so it lags price. The histogram reacts earlier than the crossovers, because it shrinks as soon as the gap between the two lines starts closing, but it still responds to price rather than predicting it.

Should the settings be changed for a shorter or longer time frame?

Many traders keep 12, 26, 9 and change the chart's bar length instead, so a weekly chart gives a slower reading and an hourly chart a faster one. Shorter periods make the lines quicker and noisier; longer ones smoother and later.