简体   繁体   English

三元运算符给出一个未声明的标识符(Pine Script)

[英]Ternary Operator gives an Undeclared identifier (Pine Script)

I have an issue with ternary operation.我对三元运算有疑问。 I have tried to add "var" - "var colFinal =...." like other posts suggested but it's giving me the same error.我试图像其他帖子建议的那样添加“var”-“var colFinal =....”,但它给了我同样的错误。

//@version=3
study(title="Guppy", shorttitle="Guppy", overlay=true)
len1 = input(3, minval=1, title="Fast EMA 1")
len2 = input(5, minval=1, title="Fast EMA 2")
len3 = input(8, minval=1, title="Fast EMA 3")
len4 = input(10, minval=1, title="Fast EMA 4")
len5 = input(12, minval=1, title="Fast EMA 5")
len6 = input(15, minval=1, title="Fast EMA 6")
//Slow EMA
len7 = input(30, minval=1, title="Slow EMA 7")
len8 = input(35, minval=1, title="Slow EMA 8")
len9 = input(40, minval=1, title="Slow EMA 9")
len10 = input(45, minval=1, title="Slow EMA 10")
len11 = input(50, minval=1, title="Slow EMA 11")
len12 = input(60, minval=1, title="Slow EMA 12")
//Fast EMA (High Price)
ema1 = ema(high, len1)
ema2 = ema(high, len2)
ema3 = ema(high, len3)
ema4 = ema(high, len4)
ema5 = ema(high, len5)
ema6 = ema(high, len6)
//Slow EMA (Close Price)
ema7 = ema(close, len7)
ema8 = ema(close, len8)
ema9 = ema(close, len9)
ema10 = ema(close, len10)
ema11 = ema(close, len11)
ema12 = ema(close, len12)

//Fast EMA Color Rules
colfastL = (ema1 > ema2 and ema2 > ema3 and ema3 > ema4 and ema4 > ema5 and ema5 > ema6)
colfastS = (ema1 < ema2 and ema2 < ema3 and ema3 < ema4 and ema4 < ema5 and ema5 < ema6)
//Slow EMA Color Rules
colslowL = ema7 > ema8 and ema8 > ema9 and ema9 > ema10 and ema10 > ema11 and ema11 > ema12 
colslowS = ema7 < ema8 and ema8 < ema9 and ema9 < ema10 and ema10 < ema11 and ema11 < ema12

doubleL = colfastL and colslowL
doubleS = colfastS and colslowS

//Fast EMA Final Color Rules
colFinal = doubleL ? aqua : doubleS ? orange : colfastL ? green : gray
//Slow EMA Final Color Rules
colFinal2 = colslowL ? lime : colslowS ? red : gray

//Fast EMA Plots
p1=plot(ema1, title="Fast EMA 1", style=line, linewidth=2, color=colFinal)
plot(ema2, title="Fast EMA 2", style=line, linewidth=1, color=colFinal)
plot(ema3, title="Fast EMA 3", style=line, linewidth=1, color=colFinal)
plot(ema4, title="Fast EMA 4", style=line, linewidth=1, color=colFinal)
plot(ema5, title="Fast EMA 5", style=line, linewidth=1, color=colFinal)
p2=plot(ema6, title="Fast EMA 6", style=line, linewidth=2, color=colFinal)
fill(p1,p2,color=colFinal, transp=60)

It is not recognizing any variables or ternary operator.它不识别任何变量或三元运算符。 This gets me errors on:这让我出错:

Add to Chart operation failed, reason: line 115: Undeclared identifier 'aqua';
line 115: Undeclared identifier 'orange';
line 115: Undeclared identifier 'green';
line 115: Undeclared identifier 'gray';
line 117: Undeclared identifier 'lime';
line 117: Undeclared identifier 'red';
line 117: Undeclared identifier 'gray';
line 119: Undeclared identifier 'line';
line 119: Undeclared identifier 'colFinal';
line 120: Undeclared identifier 'line';

What is the best and short way to solve it?解决它的最好和最简单的方法是什么?

Converted it to //@version=4 and corrected the color names.将其转换为//@version=4并更正了颜色名称。

//@version=4
study(title="Guppy", shorttitle="Guppy", overlay=true)

len1 = input(3, minval=1, title="Fast EMA 1")
len2 = input(5, minval=1, title="Fast EMA 2")
len3 = input(8, minval=1, title="Fast EMA 3")
len4 = input(10, minval=1, title="Fast EMA 4")
len5 = input(12, minval=1, title="Fast EMA 5")
len6 = input(15, minval=1, title="Fast EMA 6")

//Slow EMA
len7 = input(30, minval=1, title="Slow EMA 7")
len8 = input(35, minval=1, title="Slow EMA 8")
len9 = input(40, minval=1, title="Slow EMA 9")
len10 = input(45, minval=1, title="Slow EMA 10")
len11 = input(50, minval=1, title="Slow EMA 11")
len12 = input(60, minval=1, title="Slow EMA 12")

//Fast EMA (High Price)
ema1 = ema(high, len1)
ema2 = ema(high, len2)
ema3 = ema(high, len3)
ema4 = ema(high, len4)
ema5 = ema(high, len5)
ema6 = ema(high, len6)
//Slow EMA (Close Price)
ema7 = ema(close, len7)
ema8 = ema(close, len8)
ema9 = ema(close, len9)
ema10 = ema(close, len10)
ema11 = ema(close, len11)
ema12 = ema(close, len12)

//Fast EMA Color Rules
colfastL = (ema1 > ema2 and ema2 > ema3 and ema3 > ema4 and ema4 > ema5 and ema5 > ema6)
colfastS = (ema1 < ema2 and ema2 < ema3 and ema3 < ema4 and ema4 < ema5 and ema5 < ema6)
//Slow EMA Color Rules
colslowL = ema7 > ema8 and ema8 > ema9 and ema9 > ema10 and ema10 > ema11 and ema11 > ema12 
colslowS = ema7 < ema8 and ema8 < ema9 and ema9 < ema10 and ema10 < ema11 and ema11 < ema12

doubleL = colfastL and colslowL
doubleS = colfastS and colslowS

//Fast EMA Final Color Rules
colFinal = doubleL ? color.aqua : doubleS ? color.orange : colfastL ? color.green : color.gray
//Slow EMA Final Color Rules
colFinal2 = colslowL ? color.lime : colslowS ? color.red : color.gray

//Fast EMA Plots
p1=plot(ema1, title="Fast EMA 1", style=plot.style_line, linewidth=2, color=colFinal)
plot(ema2, title="Fast EMA 2", style=plot.style_line, linewidth=1, color=colFinal)
plot(ema3, title="Fast EMA 3", style=plot.style_line, linewidth=1, color=colFinal)
plot(ema4, title="Fast EMA 4", style=plot.style_line, linewidth=1, color=colFinal)
plot(ema5, title="Fast EMA 5", style=plot.style_line, linewidth=1, color=colFinal)
p2=plot(ema6, title="Fast EMA 6", style=plot.style_line, linewidth=2, color=colFinal)
fill(p1,p2,color=colFinal, transp=60)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM