OPEN-SOURCE SCRIPT

MACD with Histogram Difference

Von ASS_567
//version=5
indicator("MACD with Histogram Difference", shorttitle="MACD", overlay=false)

// 定义参数
fastLength = input.int(12, title="Fast EMA Length") // 快速EMA周期
slowLength = input.int(26, title="Slow EMA Length") // 慢速EMA周期
signalSmoothing = input.int(9, title="Signal Smoothing") // 信号线周期
redGreenEMALength = input.int(9, title="Red-Green EMA Length") // 红绿柱EMA周期

// 计算EMA
fastMA = ta.ema(close, fastLength)
slowMA = ta.ema(close, slowLength)

// 计算MACD线
macdLine = fastMA - slowMA

// 计算信号线
signalLine = ta.ema(macdLine, signalSmoothing)

// 计算柱状图
histogram = macdLine - signalLine

// 确定柱体颜色
var colorHist = color.new(color.gray, 100) // 默认透明色
if histogram >= 0
if histogram > histogram[1] and histogram[1] >= 0
colorHist := color.green // 上穿零轴,最高柱体
else
colorHist := color.new(color.green, 70) // 随后柱体降低为浅绿
else
if histogram < histogram[1] and histogram[1] < 0
colorHist := color.red // 下穿零轴,最低柱体
else
colorHist := color.new(color.red, 70) // 随后柱体上升为浅红

// 计算红绿柱的9日EMA
redGreenEMA = ta.ema(histogram, redGreenEMALength)

// 计算红绿柱与EMA之间的差值
difference = histogram - redGreenEMA

// 确定差值柱体颜色
var colorDiffHist = color.new(color.gray, 100) // 默认透明色
if difference >= 0
if difference > difference[1]
colorDiffHist := color.green // 差值增加
else
colorDiffHist := color.new(color.green, 70) // 差值减少
else
if difference < difference[1]
colorDiffHist := color.red // 差值降低
else
colorDiffHist := color.new(color.red, 70) // 差值上升

// 绘制MACD线
plot(macdLine, color=color.blue, title="MACD Line")

// 绘制信号线
plot(signalLine, color=color.orange, title="Signal Line")

// 绘制柱状图
plot(histogram, style=plot.style_columns, color=colorHist, title="Histogram")

// 绘制红绿柱的曲线
plot(histogram, color=(histogram >= 0 ? color.green : color.red), linewidth=2, title="Red-Green Line")

// 绘制红绿柱的9日EMA
plot(redGreenEMA, color=color.purple, linewidth=2, title="Red-Green EMA")

// 绘制差值柱状图
plot(difference, style=plot.style_columns, color=colorDiffHist, title="Difference Histogram")

// 绘制零轴
hline(0, "Zero Line", color=color.gray, linestyle=hline.style_dashed)
Candlestick analysisChart patterns

Open-source Skript

Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun das Script auch andere Trader verstehen und prüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden. Die Nutzung dieses Codes in einer Veröffentlichung wird in unseren Hausregeln reguliert. Sie können es als Favoriten auswählen, um es in einem Chart zu verwenden.

Möchten Sie dieses Skript auf einem Chart verwenden?

Haftungsausschluss