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

ta.macd() computes the MACD indicator: typically the difference between fast and slow EMAs of source (MACD line), an EMA of that line (signal), and their difference (histogram). It helps assess trend and momentum.

A MACD line crossing above the signal line is often read as bullish momentum; crossing below as bearish. Histogram expansion or contraction can reinforce whether momentum is strengthening or fading. Always combine with context and risk management.

A common default is fast 12, slow 26, signal 9 on close. These are conventions, not universal truths—tune lengths to your timeframe and instrument.

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.