How it is calculated
The MACD line is EMA(fast) minus EMA(slow) of the source, the signal line an EMA of the MACD line over the signal length, the histogram MACD minus signal. Every EMA is seeded with the plain mean of its own first values, so the line is exactly the difference of the two ema lines. TA-Lib MACD seeds the fast average later so both start together; the values agree once that seed has decayed. After Appel 1979.
Reference: TA-Lib MACD (Appel 1979)
How to read it
Above zero the fast average is over the slow one, below zero under it. MACD crossing its signal line, or the histogram changing sign, marks a change of pace; divergences between price and MACD hint at a fading move. The values are in price units and cannot be compared across markets. In a sideways market the lines cross often and say little.
In a strategy
A trend entry when the MACD line crosses above its signal: ctx.ind("macd", fast=12, slow=26, signal=9) gives .macd, .signal and .hist; buy when .hist turns positive, often only while .macd is above zero.
Inputs
| Input | Type | Default | Range or choices |
|---|---|---|---|
Fast lengthfast | Whole number | 12 | min 1, max 5000 |
Slow lengthslow | Whole number | 26 | min 1, max 5000 |
Signal lengthsignal | Whole number | 9 | min 1, max 5000 |
Sourcesource | Price | "close" | close, open, high, low, hl2, hlc3, ohlc4, hlcc4 |
What it draws
| Line | Drawn as |
|---|---|
| MACD | Line |
| Signal | Line |
| Histogram | Columns |
Guide lines at 0.
Used in
No strategy template reads it yet.