What this builds
- MACD line (fast EMA - slow EMA)
- Signal line (EMA of MACD)
- Histogram (MACD - signal) with green/red coloring
- Zero line reference
Full script
With divergence coloring
Color the MACD line based on whether it is above or below the signal:Understanding the return value
ta.macd returns an object with three fields:
| Field | Description |
|---|---|
macd | Fast EMA minus slow EMA |
signal | EMA of macd over sigLen bars |
hist | macd minus signal |
NaN during the warmup period (first slowLen + sigLen - 2 bars approximately).
Histogram color tip
The histogram usescolorUp and colorDown based on whether the value is positive or negative:
hist > 0(MACD above signal) usescolorUphist <= 0(MACD below signal) usescolorDown
Related pages
Oscillators
ta.macd function reference.
Plot styles
histogram style and colorUp/colorDown options.
NaN handling
Why na(m.macd) check is needed during warmup.