Pine Script合并Wave Trend Oscillator与MACD时脚本无法解析报错求解
问题原因
你代码的核心错误有两点:
- 开头的指标声明被注释,同时缺失Pine Script版本声明,导致编译器无法识别语法规则,解析
input.string的选项参数时出错,对应你收到的报错信息。 - 混用了Pine Script v4的过时语法,包括用数字指定plot样式、
transp参数写法,在当前TradingView默认的v5环境下无法运行。
修正后完整可运行代码
//@version=5 indicator("WaveTrend + MACD", shorttitle="WT+MACD", overlay=false) // Wave Trend 配置 n1 = input.int(10, "Channel Length") n2 = input.int(21, "Average Length") obLevel1 = input.int(60, "Over Bought Level 1") obLevel2 = input.int(53, "Over Bought Level 2") osLevel1 = input.int(-60, "Over Sold Level 1") osLevel2 = input.int(-53, "Over Sold Level 2") ap = hlc3 esa = ta.ema(ap, n1) d = ta.ema(math.abs(ap - esa), n1) ci = (ap - esa) / (0.015 * d) tci = ta.ema(ci, n2) wt1 = tci wt2 = ta.sma(wt1,4) // Wave Trend 绘图 plot(0, color=color.gray) plot(obLevel1, color=color.red) plot(osLevel1, color=color.green) plot(obLevel2, color=color.red, style=plot.style_dashed) plot(osLevel2, color=color.green, style=plot.style_dashed) plot(wt1, color=color.green) plot(wt2, color=color.red, style=plot.style_dashed) plot(wt1-wt2, color=color.new(color.blue, 80), style=plot.style_area) // MACD 配置 fast_length = input.int(title="Fast Length", defval=12) slow_length = input.int(title="Slow Length", defval=26) src = input(close, title="Source") signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9) sma_source = input.string(title="Oscillator MA Type", defval="EMA", options=["SMA", "EMA"]) sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"]) // MACD 颜色配置 col_macd = input(#2962FF, "MACD Line ", group="Color Settings", inline="MACD") col_signal = input(#FF6D00, "Signal Line ", group="Color Settings", inline="Signal") col_grow_above = input(#26A69A, "Above Grow", group="Histogram", inline="Above") col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above") col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below") col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below") // MACD 计算 fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length) slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length) macd = fast_ma - slow_ma signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length) hist = macd - signal // MACD 绘图 plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below))) plot(macd, title="MACD", color=col_macd) plot(signal, title="Signal", color=col_signal)
内容的提问来源于stack exchange,提问作者Krishnendu Bhattacharyya
相关产品推荐
相关产品推荐

