OPEN-SOURCE SCRIPT

MACD with Histogram Difference

Oleh 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

Skrip sumber terbuka

Dalam semangat sebenar TradingView, penulis telah menerbitkan kod Pine ini sebagai sumber terbuka supaya pedagang dapat memahami dan mengesahkannya. Sorakan kepada penulis! Anda boleh menggunakan perpustakaan ini secara percuma, tetapi penggunaan semula kod dalam penerbitan ini adalah dikawal oleh Peraturan dalaman. Anda boleh menyukainya untuk menggunakannya pada carta.

Ingin menggunakan skrip ini pada carta?

Penafian