Part of the Indicator Math series. This time, we’ll separate the gap between two price averages from the gap shown by the histogram.

Which zero did MACD just cross?

Watch the histogram turn negative and you might think the faster moving average just fell below the slower one. Look at the price chart, though, and the faster average may still be well above the slower one. Both displays can be right. They’re measuring two different gaps.

MACD stands for Moving Average Convergence Divergence. Convergence means the two averages are drawing together; divergence means they’re spreading apart. The MACD line shows their signed difference. The histogram compares that difference with a smoothed version of itself. Before you build a rule around a “MACD cross,” specify which comparison you mean.

The MACD formula

StockCharts’ MACD guide credits Gerald Appel with developing MACD in the late 1970s and lists 12, 26, and 9 as the typical settings today. In his history of the indicator, technical analyst Greg Morris notes that Appel’s original design used different parameters for buy and sell signals, rather than applying the now-standard combination to both. Thomas Aspray added the histogram to make the difference between MACD and its signal line easier to see.

Fast EMA = 12-bar EMA of closes
Slow EMA = 26-bar EMA of closes
MACD line = Fast EMA − Slow EMA
Signal line = 9-bar EMA of the MACD line
Histogram = MACD line − Signal line

EMA weight = 2 ÷ (Length + 1)
New EMA = Old EMA + Weight × (New input − Old EMA)

EMA means exponential moving average. Each new value moves the EMA toward the new input by a fraction of the gap. The fraction is about 15.38% for the 12-bar EMA, 7.41% for the 26-bar EMA, and 20% for the 9-bar EMA. The first two averages use the same new closing price. The third uses the new MACD value, not the closing price. Lengths count bars, so 12 bars on a five-minute chart do not represent the same trading history as 12 bars on a daily chart.

Some platforms let you change the price input or the type of average used in either step. For example, TradingView’s MACD settings let you choose between EMA and simple moving average (SMA) for the fast and slow averages and for the signal line. The calculations here use closes and EMAs throughout. Check those inputs before comparing two charts.

A worked MACD example by hand

Suppose a made-up stock has already closed at $100 for 40 bars. Start the spreadsheet on the last flat bar, labeled Day 0. Both price EMAs are $100, their gap is zero, and the signal line is zero too. The flat history gives you starting values while keeping the example short. It isn’t a recommendation to initialize a real chart at zero or trust its first few bars.

Day 1 fast = 100 + (2 ÷ 13) × (102 − 100)
           ≈ 100.307692
Day 1 slow = 100 + (2 ÷ 27) × (102 − 100)
           ≈ 100.148148
Day 1 MACD = Fast EMA − Slow EMA ≈ 0.159544
Day 1 signal = 0 + (2 ÷ 10) × (Day 1 MACD − 0)
             ≈ 0.031909
Day 1 histogram = Day 1 MACD − Day 1 signal
                ≈ 0.127635

To carry it forward, each day starts with the previous row’s two price EMAs and signal line. Update the price EMAs first, subtract for the MACD line, then update the signal with that day’s MACD and subtract for the histogram. Keep the sheet’s precision and round only for display, as in the table below.

DayCloseFastSlowMACDSignal
0100.00100.0000100.00000.00000.0000
1102.00100.3077100.14810.15950.0319
2104.00100.8757100.43350.44230.1140
3106.00101.6641100.84580.81830.2548
4106.00102.3312101.22761.10360.4246
5105.00102.7417101.50701.23470.5866
6104.00102.9353101.69171.24360.7180
7103.00102.9453101.78861.15670.8057
8102.00102.7998101.80430.99560.8437
9101.00102.5229101.74470.77830.8306

Subtract the signal column from MACD to build the histogram in a seventh spreadsheet column. From Day 4 to Day 5 it shrinks from about +0.6790 to +0.6481 even as the gap between the price averages grows. By Day 9 the histogram is about −0.0524, yet MACD is still positive at about +0.7783. The signal line has passed MACD while the slow price average remains below the fast one.

What MACD actually measures

The MACD line measures how far apart the fast and slow price averages are and which one is higher. Above zero, fast is above slow. Below zero, fast is below slow. The histogram measures how far the MACD line is from its own smoothed value and on which side. A negative histogram means MACD is below its signal, not necessarily below zero. A shrinking positive histogram means MACD is getting closer to its signal, not necessarily that the two price averages are closing in on each other.

The chart below aligns daily SPY prices and the two price averages with MACD, its signal line, and the histogram. Follow the histogram from its April peak into early May. It shrinks toward zero while the fast average stays above the slow one and SPY trades higher.

SPY daily candles with 12- and 26-day EMAs above a MACD panel; the green histogram shrinks in late April as price rises.
SPY daily, Feb 2–Jun 30, 2026, with MACD(12, 26, 9): the histogram peaked at 6.57 on Apr 17 and shrank to 0.98 by May 5 while MACD stayed near 12.7.

MACD is a way to describe changes in the spread between two smoothed views of price. It doesn’t measure buying volume, directly measure acceleration in price, or say how far the next move could go. The reading is in the same units as the input, such as dollars per share or futures index points. Unlike RSI, it has no fixed 0 to 100 scale. A reading of 2 on two different markets doesn’t mean the trend has the same strength in both.

Imagine a stock that keeps rising by about a dollar per bar. After the initial adjustment, both price averages can rise at about the same pace while the faster one stays ahead. Their gap then changes very little. As the signal line catches up to that nearly steady gap, the histogram can sit near zero even while price keeps climbing. A quiet histogram isn’t the same thing as a quiet market.

How traders use MACD

  • Higher-timeframe trend filter: Test taking an MES long setup only when the last completed 30-minute MACD line is above zero. Use price structure on your execution chart to make the entry decision. If you’re already requiring the 12 EMA to be above the 26 EMA on that 30-minute chart, this adds nothing.
  • Pullback timing: In an uptrend that has held its prior swing low, test waiting for the histogram to cross back above zero before taking your predefined price trigger. Set the number of bars the trigger can stay valid after the cross. A histogram flip also happens in sideways trade, so define the pullback and the trend independently.
  • Trade management: In a profitable long trend trade, test raising your stop to just below the last swing low after two completed bars with a negative histogram, but only if price is still above the swing and the change brings your stop closer. Compare that exit rule with your usual exit plan. Keep the original protective stop until your rule calls for an update.

Where MACD fails

Sideways trade can produce repeated crosses. When price oscillates inside a narrow range, the averages can keep changing order without a lasting directional move. On a sharp reversal, the averages may take time to catch up. Shorter lengths generally put more weight on new inputs, which can speed up the response but can also produce more flips. Compare settings using the same backtesting rules, not whichever picture looks cleanest after the move.

A live crossover can fail to survive the close. The unfinished close feeds both price averages, then the MACD line, signal line, and histogram. TradingView’s repainting guide distinguishes that live movement from the confirmed values you see on historical bars. If you test a 30-minute crossover on a five-minute chart, wait for the 30-minute close, not just the close of the smaller bar.

Starting values matter at the start of a test. Each EMA carries some of its previous value forward, including the signal EMA. If your spreadsheet starts on the first day you plan to score trades, its early reads may not match a chart that has been running longer. Load earlier data to let the averages settle before scoring your rules.

Three readings aren’t three independent votes. Both price averages come from the same closes. The signal and histogram are derived from their difference. If the fast average is already part of your setup, write down what information MACD adds before you spend time testing it. Requiring the histogram to be positive and the MACD line to be above its signal is writing the same rule twice.

Takeaway: The MACD line is the gap between two price averages. The histogram is the gap between MACD and its signal. Decide which gap matters to your setup, spell out the timeframe and bar-close rule, and test it against the same setup without MACD.

Next up: The Stochastic Oscillator: Where Price Closed Inside Its Range

Leave a Reply