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:
Script de código aberto

Dentro do verdadeiro espírito TradingView, o autor deste script publicou ele como um script de código aberto, para que os traders possam compreender e checar ele. Um viva ao autor! Você pode usá-lo gratuitamente, mas a reutilização deste código em uma publicação é regida pelas Regras da Casa. Você pode favoritá-lo para usá-lo em um gráfico.

Aviso legal

As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.

Quer usar esse script no gráfico?
//@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)