ta.macd()
Moving Average Convergence Divergence
MACD (moving average convergence/divergence) is a trend-following momentum indicator.
Syntax
ta.macd(source, fastlen, slowlen, siglen) → [series float, series float, series float]Arguments
| Parameter | Type | Description |
|---|---|---|
| source | series int/float | Price or value series (commonly close). |
| fastlen | simple int | Fast EMA length. |
| slowlen | simple int | Slow EMA length. |
| siglen | simple int | Signal line EMA length (applied to the MACD line). |
Returns
Tuple of three MACD series: MACD line, signal line, and histogram line.
Code Examples
//@version=6
indicator("ta.macd")
[macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9)
plot(macdLine, color=color.blue)
plot(signalLine, color=color.orange)
plot(histLine, color=color.red, style=plot.style_histogram)Trading Applications
Identify trend direction and momentum
Generate signals from MACD/signal line crossovers
Detect divergences for reversal trading
Use histogram for momentum strength analysis
Frequently Asked Questions
Generate ta.macd() Code with AI
Skip the manual coding. Use Pineify's AI Coding Agent to generate Pine Script code using ta.macd() and other built-in functions instantly.
Related Pine Script Functions
ta.ema() - Exponential Moving Average
Learn how to use ta.ema() in Pine Script. Syntax, parameters, code examples, and trading applications for the Exponential Moving Average function.
ta.sma() - Simple Moving Average
Learn how to use ta.sma() in Pine Script. Syntax, parameters, code examples, and trading applications for the Simple Moving Average function.
ta.dmi() - Directional Movement Index
Learn how to use ta.dmi() in Pine Script. Syntax, parameters, code examples for +DI, -DI, and ADX.
ta.supertrend() - Supertrend
Learn how to use ta.supertrend() in Pine Script. Syntax, parameters, code examples for the ATR-based trend overlay.
ta.sar() - Parabolic SAR
Learn how to use ta.sar() in Pine Script. Syntax, parameters, code examples for the Parabolic Stop and Reverse indicator.