dashed

MACD Colors

147
This adds visual cue for when MACD histogram bars is decreasing when above the zero-line, and increasing when below the zero-line.

Based on:
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
//@version=2
study("MACD Colors", overlay = false)

// This adds visual cue for when MACD histogram bars is decreasing when above the zero-line, and
// when increasing when below the zero-line.
// 
// Based on: https://www.tradingview.com/script/4IYKX938-MACD-4C/

fastMA = input(title="Fast Length", type = integer, defval = 12)
slowMA = input(title="Slow Length", type = integer, defval = 26)
src = input(title="Source", type=source, defval=close)
signalSmooth = input(title="Signal smoothing", type = integer, defval = 9)
sma_macd = input(title="Simple MA (for MACD line)", type = bool, defval = false)
sma_signal = input(title="Simple MA (for signal line)", type = bool, defval = false)

MACDLine =  if sma_macd
    sma(src, fastMA) - sma(src, slowMA)
else 
    ema(src, fastMA) - ema(src, slowMA)
    
SignalLine = if sma_signal
    sma(MACDLine, signalSmooth)
else
    ema(MACDLine, signalSmooth)

MACDHistogram = MACDLine - SignalLine

plotColor = if MACDHistogram > 0
    MACDHistogram > MACDHistogram[1] ? lime : green
else 
    MACDHistogram < MACDHistogram[1] ? maroon : red

plot(MACDLine, style = line, color = blue)
plot(SignalLine, style = line, color = orange)
plot(MACDHistogram, style = columns, color = plotColor)
plot(0, title = "Zero line", linewidth = 1, color = gray)