TrendPine Script v6

ta.macd()

Moving Average Convergence Divergence

MACD (moving average convergence/divergence) is a trend-following momentum indicator.

Syntax

Syntax
ta.macd(source, fastlen, slowlen, siglen) → [series float, series float, series float]

Arguments

ParameterTypeDescription
sourceseries int/floatPrice or value series (commonly close).
fastlensimple intFast EMA length.
slowlensimple intSlow EMA length.
siglensimple intSignal line EMA length (applied to the MACD line).

Returns

Tuple of three MACD series: MACD line, signal line, and histogram line.

Code Examples

Pine Script v6 Example
//@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

Related Functions

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.