OPEN-SOURCE SCRIPT

MACD Color Shift

117
//version=5
// Title: MACD with Color Intensity
indicator("MACD Color Shift", overlay = false)

// MACD Inputs
fast_length = input.int(12, "Fast Length", minval=1)
slow_length = input.int(26, "Slow Length", minval=1)
signal_length = input.int(9, "Signal Length", minval=1)

// MACD Calculation
[macdLine, signalLine, hist] = ta.macd(close, fast_length, slow_length, signal_length)

// Calculate momentum (rate of change) to determine color intensity
macdMomentum = ta.change(macdLine)
histMomentum = ta.change(hist)

// Define color conditions
// For Histogram
lightGreen = hist > 0 and histMomentum >= 0
darkGreen = hist > 0 and histMomentum < 0
lightRed = hist < 0 and histMomentum <= 0
darkRed = hist < 0 and histMomentum > 0

// Plot MACD Line
plot(macdLine, "MACD", color=color.blue, linewidth=1)

// Plot Signal Line
plot(signalLine, "Signal", color=color.orange, linewidth=1)

// Plot Histogram with conditional colors
plot(hist, "Histogram", style=plot.style_histogram,
color=lightGreen ? #90EE90 : darkGreen ? #006400 : lightRed ? #FFB6C1 : #8B0000)

// Plot zero line
plot(0, "Zero", color=color.gray, linewidth=1)

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.