Moving average convergence divergence
All indicators

LibraryMomentum

Indicator

Moving average convergence divergence

The gap between a fast and a slow exponential average of price, with a signal line and a histogram, to show the direction of a trend and when it gains or loses pace.

MomentumOwn pane4 inputsMACD

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

InputTypeDefaultRange or choices
Fast lengthfastWhole number12min 1, max 5000
Slow lengthslowWhole number26min 1, max 5000
Signal lengthsignalWhole number9min 1, max 5000
SourcesourcePrice"close"close, open, high, low, hl2, hlc3, ohlc4, hlcc4

What it draws

LineDrawn as
MACDLine
SignalLine
HistogramColumns

Guide lines at 0.

Used in

No strategy template reads it yet.

OrionQuant