Sidechair

ta.macd()

Browse the reference

Returns three series: the MACD line (fast EMA minus slow EMA), its signal line, and the histogram between them.

Try it in the editor

ta.macd computes the MACD line as ta.ema(source, fastlen) - ta.ema(source, slowlen), the signal line as ta.ema of that line over siglen bars, and the histogram as MACD minus signal. It returns them as a tuple, in that order.

The MACD line first appears on bar number slowlen, the signal and histogram on bar number slowlen + siglen - 1. Assign the result to three names: [macdLine, signalLine, hist] = ta.macd(close, 12, 26, 9).

Syntax

Pine Script
ta.macd(source: series int/float, fastlen: simple int, slowlen: simple int, siglen: simple int) -> [series float, series float, series float]

Arguments

NameTypeDefaultDescription
sourceseries int/floatrequiredSeries to run the averages on, usually close.
fastlensimple intrequiredLength of the fast EMA. A whole number of 1 or more.
slowlensimple intrequiredLength of the slow EMA. A whole number of 1 or more.
siglensimple intrequiredLength of the EMA that smooths the MACD line into the signal. A whole number of 1 or more.

Returns

[series float, series float, series float]: the MACD line, the signal line and the histogram, each a series of floats.

Remarks

  • The histogram crosses zero exactly when the MACD line crosses the signal line.
  • Swapping fastlen and slowlen flips the sign of the MACD line.

Example

Pine ScriptMACD with histogram columnsOpen in editor
//@version=6
indicator("MACD")
[macdLine, signalLine, hist] = ta.macd(close, 12, 26, 9)
plot(hist, "Histogram", color = hist >= 0 ? color.teal : color.maroon, style = plot.style_columns)
plot(macdLine, "MACD", color = color.blue)
plot(signalLine, "Signal", color = color.orange)

See also

Runs on Sidechair