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:
開源腳本

本著真正的TradingView精神,該腳本的作者將其開源發布,以便交易者可以理解和驗證它。為作者喝彩吧!您可以免費使用它,但在出版物中重複使用此代碼受網站規則的約束。 您可以收藏它以在圖表上使用。

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。

想在圖表上使用此腳本?
//@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)