# MACD: line, signal and histogram

> How MACD is built from two EMAs, and what its three outputs in the graph editor mean.

Source: https://quantraider.com/learn/indicators/macd

Course: Technical indicators (lesson 3 of 6) · Level: Intermediate · 4 min

MACD turns two exponential moving averages into a momentum line, a smoothed signal line and a histogram. You will learn how each output is calculated with the standard 12/26/9 settings and how they map to the three outputs of the `MACD` node.

## Three outputs from two EMAs

**MACD** stands for moving average convergence divergence. The MACD line is the difference between a fast and a slow EMA of the close. It is positive when the fast average is above the slow one, which means recent prices are higher than the longer-term average, and negative when it is below.

The **signal line** is an EMA of the MACD line itself, so it is a slower version of the same thing. The **histogram** is the gap between the two, which shows whether MACD is pulling away from its signal or falling back to it.

```
MACD = EMA12(Close) − EMA26(Close)
Signal = EMA9(MACD)
Histogram = MACD − Signal
```

The standard 12/26/9 settings: fast period 12, slow period 26, signal period 9.

## A numeric step

**Worked example: One MACD update with 12/26/9**

1. The fast EMA uses α = 2 / (12 + 1) = 0.1538. With a previous EMA12 of 104.80 and a close of 106.00, EMA12 = 104.80 + 0.1538 × (106.00 − 104.80) = 104.80 + 0.1846 = 104.98 (rounded).
2. Suppose the current EMA26 is 104.50. Then MACD = 104.98 − 104.50 = 0.48.
3. The signal EMA uses α = 2 / (9 + 1) = 0.2. With a previous signal of 0.40, Signal = 0.2 × 0.48 + 0.8 × 0.40 = 0.096 + 0.320 = 0.416.
4. Histogram = 0.48 − 0.416 = 0.064. The figures above use the rounded values shown.

MACD is 0.48, Signal is about 0.42 and the Histogram is about 0.06, so MACD is above its signal.

The numbers 12, 26 and 9 are a long-standing convention, not a result of optimisation. Other settings, such as a faster 8/17/9, give a more reactive line that crosses more often and produces more false starts. Changing them trades smoothness against lag in the same way as any moving average.

## Reading the three lines

- **MACD above zero** means the fast EMA is above the slow EMA. Its distance from zero reflects how far apart they are.
- **MACD crossing above Signal** is the same event as the histogram changing from negative to positive.
- **Histogram growing** means MACD is moving away from its signal faster. A shrinking histogram means the gap is closing, which can happen before a crossing.

MACD inherits the lag of the EMAs it is built from, and the signal line adds a second layer of smoothing, so a crossing of MACD and Signal is later than a move in price. Its absolute values also depend on the price level of the market, so a fixed threshold such as 0.5 means different things on different instruments. Comparing MACD with zero or with its signal is more portable.

**How the histogram relates to the other two lines.**

| Histogram | MACD versus Signal | Meaning |
| --- | --- | --- |
| Positive and rising | MACD above Signal, gap widening | Momentum is increasing |
| Positive and falling | MACD above Signal, gap narrowing | Momentum is fading |
| Negative | MACD below Signal | Momentum is weaker than its recent average |

> **Same data, different view**
>
> MACD uses only closes, just like moving averages. A MACD crossing and a crossing of the 12 and 26 EMAs are closely related, so they are not independent confirmations of each other.

## In the graph editor

The `MACD` node has one input socket, `Data`, and three output sockets: `Histogram`, `MACD` and `Signal`. Its settings are `Fast period`, `Slow period` and `Signal period`, which you fill in yourself, for example 12, 26 and 9.

To detect the line crossing above its signal, connect `MACD` to input A and `Signal` to input B of a `GreaterThan` node, and combine it with a `PreviousValue` check as shown in the strategy-building course. Connect `Histogram` to a `VisualizeHistogram` node to draw the bars.

> **See the histogram**: Connect `Data.Close` to a `MACD` node and its `Histogram` output to a `VisualizeHistogram` node. [Open the graph editor](https://quantraider.com/nodesystem)

## Key takeaways

- MACD = EMA12 − EMA26, Signal = EMA9 of MACD and Histogram = MACD − Signal with the standard settings.
- The histogram changes sign exactly when MACD crosses its signal line.
- MACD is built from EMAs of the close, so it lags price and is not independent of moving-average rules.
- The `MACD` node outputs `Histogram`, `MACD` and `Signal`, and its three periods are set by you.

> Educational content, not financial advice. Trading involves risk of loss.
