为什么这些代码不能在Pine Script中运行? “未声明的标识符”错误

问题描述

所以我在Pine Editor上收到有关颜色的以下未声明的标识符错误

line 23: Undeclared identifier 'red';
line 24: Undeclared identifier 'blue';
line 25: Undeclared identifier 'white';
line 36: Undeclared identifier 'blue';
line 36: Undeclared identifier 'white';
line 50: Undeclared identifier 'red';
line 50: Undeclared identifier 'black'

这是我正在运行的代码。如您所见,我正在运行版本4。

//@version=4
    study("Simple Trading",overlay = true)
 
ma5 = sma(close,5)
ma10 = sma(close,10)
ma30 = sma(close,30)
 
src1 = input(close,title = "RSI Source")
rsil = input(14,minval = 1,title = "RSI Length")
rsi30 = input(30,title = "Buy w/RSI < ")
rsi70 = input(70,title = "Sell w/RSI > ")
 
src2 = input(close,title = "Stoch Source")
kdk = input(9,title = "Stoch K")
kdd = input(3,title = "Stoch D")
kds = input(3,title = "Stoch Smooth")
kd20 = input(20,title = "Buy w/Stoch <")
kd80 = input(80,title = "Sell w/Stoch >")
 
plot(ma5,color = red)
plot(ma10,color = blue)
plot(ma30,color = white)
 
//main------------------------------------
_falling = falling(ma30,20)
fiveless = ma5 < ma30
tenless = ma10 < ma30
armbuy = fiveless and tenless and _falling
rsi = rsi(src1,rsil) < rsi30
greencandle = close > open and close[1] <= open[1] and close>close[1]
strongbuyhere = armbuy and rsi and greencandle
 
plotshape(strongbuyhere,style = shape.labelup,color = blue,location = location.belowbar,size = size.small,text = "Buy",textcolor = white)
alertcondition(strongbuyhere,title = "Strong Buy Position",message = "Buy")
plot(valuewhen(strongbuyhere,close,0))
 
 
//reverse---------------------------------
r_falling = rising(ma30,20)
rfiveless = ma5 > ma30
rtenless = ma10 > ma30
rarmbuy = rfiveless and rtenless and r_falling
rrsi = rsi(src1,rsil) > rsi70
rgreencandle = close < open and close[1] > open[1]
rstrongbuyhere = rarmbuy and rrsi and rgreencandle
 
plotshape(rstrongbuyhere,style = shape.labeldown,color = red,location = location.abovebar,text = "Sell",textcolor = black)
alertcondition(rstrongbuyhere,title = "Strong Sell Position",message = "Sell")
plot(valuewhen(rstrongbuyhere,0))''' 

有人知道我该如何解决以及我做错了什么吗?

谢谢

解决方法

您正在使用pinescript版本4(第1行://@version=4)。 在版本4中,颜色用color.前缀命名:

例如https://www.tradingview.com/pine-script-reference/#var_color{dot}red

color.red
color.blue
color.black

color.new函数https://www.tradingview.com/pine-script-reference/#fun_color{dot}new