Returns three series: the MACD line (fast EMA minus slow EMA), its signal line, and the histogram between them.
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
ta.macd(source: series int/float, fastlen: simple int, slowlen: simple int, siglen: simple int) -> [series float, series float, series float]Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| source | series int/ | required | Series to run the averages on, usually close. |
| fastlen | simple int | required | Length of the fast EMA. A whole number of 1 or more. |
| slowlen | simple int | required | Length of the slow EMA. A whole number of 1 or more. |
| siglen | simple int | required | Length 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
//@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