Pine 脚本 - if / else if 语句
我收到错误:第 56 行:不匹配的输入“if”期望“行结束而没有行继续”。在我的代码上,但是当我删除其下的某些代码行时,错误消失并且代码编译。
这里是带有错误的代码(第 56 行是第三行):
SL = if long == 'long' and (close[1]-low[1])/low[1] > 0.012
Truncate(low[1], 2)
else if long == 'long' and (close[1]-low[1])/low[1] < 0.012
Truncate(low[1]-low[1]*0.017, 2)
else if long == 'long_renversement' and renversement_red_golong == 'yes'
Truncate(math.avg(low[1], close[1]), 2)
else if long == 'long_renversement' and renversement_green_golong == 'yes'
Truncate(math.avg(low[1], open[1]), 2)
else if long == 'long_continuation' and (close[1]-(math.avg(close[1], open[1]))/(math.avg(close[1], open[1]) > 0.012
Truncate(math.avg(close[1], open[1]), 2)
else if long == 'long_continuation' and (close[1]-(math.avg(close[1], open[1]))/(math.avg(close[1], open[1]) < 0.012
Truncate(open[1], 2)
else if short == 'short' and (high[1]-close[1])/close[1] > 0.012
Truncate(high[1], 2)
else if short == 'short' and (high[1]-close[1])/close[1] < 0.012
Truncate(high[1]+high[1]*0.017, 2)
else if short == 'short_renversement' and renversement_red_goshort == 'yes'
Truncate(math.avg(high[1], open[1]), 2)
else if short == 'short_renversement' and renversement_green_goshort == 'yes'
Truncate(math.avg(high[1], close[1]), 2)
else if short == 'short_continuation' and ((math.avg(close[1], open[1])-close[1])/close[1] > 0.012
Truncate(math.avg(close[1], open[1]), 2)
else if short == 'short_continuation' and ((math.avg(close[1], open[1])-close[1])/close[1] < 0.012
Truncate(open[1], 2)
这里是我删除它末尾时的代码(运行时没有任何错误):
SL = if long == 'long' and (close[1]-low[1])/low[1] > 0.012
Truncate(low[1], 2)
else if long == 'long' and (close[1]-low[1])/low[1] < 0.012
Truncate(low[1]-low[1]*0.017, 2)
else if long == 'long_renversement' and renversement_red_golong == 'yes'
Truncate(math.avg(low[1], close[1]), 2)
else if long == 'long_renversement' and renversement_green_golong == 'yes'
Truncate(math.avg(low[1], open[1]), 2)
如果我删除的内容少于该代码,错误将保留在那里......我是很困惑...
I get the error : line 56: Mismatched input 'if' expecting 'end of line without line continuation'. on my code BUT when I delete some line of code under it the error disappear and the code compile.
Here the code with the error (line 56 is the 3rd line) :
SL = if long == 'long' and (close[1]-low[1])/low[1] > 0.012
Truncate(low[1], 2)
else if long == 'long' and (close[1]-low[1])/low[1] < 0.012
Truncate(low[1]-low[1]*0.017, 2)
else if long == 'long_renversement' and renversement_red_golong == 'yes'
Truncate(math.avg(low[1], close[1]), 2)
else if long == 'long_renversement' and renversement_green_golong == 'yes'
Truncate(math.avg(low[1], open[1]), 2)
else if long == 'long_continuation' and (close[1]-(math.avg(close[1], open[1]))/(math.avg(close[1], open[1]) > 0.012
Truncate(math.avg(close[1], open[1]), 2)
else if long == 'long_continuation' and (close[1]-(math.avg(close[1], open[1]))/(math.avg(close[1], open[1]) < 0.012
Truncate(open[1], 2)
else if short == 'short' and (high[1]-close[1])/close[1] > 0.012
Truncate(high[1], 2)
else if short == 'short' and (high[1]-close[1])/close[1] < 0.012
Truncate(high[1]+high[1]*0.017, 2)
else if short == 'short_renversement' and renversement_red_goshort == 'yes'
Truncate(math.avg(high[1], open[1]), 2)
else if short == 'short_renversement' and renversement_green_goshort == 'yes'
Truncate(math.avg(high[1], close[1]), 2)
else if short == 'short_continuation' and ((math.avg(close[1], open[1])-close[1])/close[1] > 0.012
Truncate(math.avg(close[1], open[1]), 2)
else if short == 'short_continuation' and ((math.avg(close[1], open[1])-close[1])/close[1] < 0.012
Truncate(open[1], 2)
And here the code when i delete the end of it (run without any error) :
SL = if long == 'long' and (close[1]-low[1])/low[1] > 0.012
Truncate(low[1], 2)
else if long == 'long' and (close[1]-low[1])/low[1] < 0.012
Truncate(low[1]-low[1]*0.017, 2)
else if long == 'long_renversement' and renversement_red_golong == 'yes'
Truncate(math.avg(low[1], close[1]), 2)
else if long == 'long_renversement' and renversement_green_golong == 'yes'
Truncate(math.avg(low[1], open[1]), 2)
If I delete less than that, the error stay there... I'm so confused...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编译器错误没有帮助,但问题是 if/else 块中有几个放错位置的括号(这被视为单个块,这就是为什么编译器将您发送到块开始的行而不是实际的行)符合问题):
修复这些问题,代码应该可以正确编译。
The compiler error is not helpful, but the issue is that you have several misplaced brackets in your if/else block (which is counted as a single block, which is why the compiler sends you to the line where the block starts instead of the actual line with the issue):
Fix these and the code should compile properly.