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)