Pine Script编译报错求助:请指出EMA与VWAP绘图代码错误
代码错误分析与修正
存在的错误点:
- 内置颜色调用语法错误:Pine Script中内置颜色需通过
color.前缀引用,代码里的color=red不符合规范,应改为color=color.red或对应十六进制色值#FF0000。 - VWAP未正确调用函数:TradingView里的VWAP不能直接用
vwap变量访问,必须调用vwap()函数获取数据。
修正后的完整代码:
//@version=5 indicator("EMA & VWAP", overlay=true) plot(ema(close,9), color=color.red, linewidth=1) plot(ema(close,21), color=#5878DA, linewidth=1) plot(ema(close,50), color=#297F87, linewidth=1) plot(ema(close,200), color=#83d13a, linewidth=1, style=plot.style_circles) plot(vwap(), color=#FFB830, linewidth=2, style=plot.style_cross)
补充说明:
- 开头添加
//@version=5指定Pine Script 5版本(当前TradingView主流版本),并通过indicator()声明指标名称与叠加属性,确保指标显示在K线图上。 - 修正了颜色调用与VWAP函数调用的语法问题,代码可正常编译运行。
内容的提问来源于stack exchange,提问作者S GUPTA
相关产品推荐
相关产品推荐

