// MACD柱子面积计算指标 // 作者: Claude AI // 版本: 1.0 //@version=5 indicator("MACD柱子面积", shorttitle="MACD面积", overlay=false) // MACD参数 fast_length = input.int(12, "快线长度", minval=1) slow_length = input.int(26, "慢线长度", minval=1) signal_length = input.int(9, "信号线长度", minval=1) // 计算MACD [macdLine, signalLine, histLine] = ta.macd(close, fast_length, slow_length, signal_length) // 初始化面积变量 var float upArea = 0.0 var float downArea = 0.0 // 检测柱子正负性并累加面积 if histLine > 0 upArea := upArea + histLine // 当从负值转为正值时,重置下跌面积 if histLine[1] < 0 downArea := 0.0 else if histLine < 0 downArea := downArea + math.abs(histLine) // 当从正值转为负值时,重置上涨面积 if histLine[1] > 0 upArea := 0.0 // 绘制结果 plot(upArea, "上涨段面积", color=color.green, style=plot.style_area) plot(downArea, "下跌段面积", color=color.red, style=plot.style_area) plot(histLine, "MACD柱状图", color=histLine >= 0 ? color.green : color.red, style=plot.style_histogram) plot(macdLine, "MACD", color=color.blue) plot(signalLine, "信号线", color=color.orange) // 添加文字标签 var label upLabel = na var label downLabel = na if barstate.islast upLabel := label.new( bar_index, upArea, text="上涨面积: " + str.tostring(upArea, "#.##"), color=color.green, style=label.style_label_down, textcolor=color.white) downLabel := label.new( bar_index, downArea, text="下跌面积: " + str.tostring(downArea, "#.##"), color=color.red, style=label.style_label_up, textcolor=color.white) label.delete(upLabel[1]) label.delete(downLabel[1])