Pine 脚本 - if / else if 语句

发布于 2025-01-11 00:22:53 字数 2125 浏览 0 评论 0原文

我收到错误:第 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

刘备忘录 2025-01-18 00:22:53

编译器错误没有帮助,但问题是 if/else 块中有几个放错位置的括号(这被视为单个块,这就是为什么编译器将您发送到块开始的行而不是实际的行)符合问题):

// Five opening brackets, three closing brackets
else if long == 'long_continuation' and (close[1]-(math.avg(close[1], open[1]))/(math.avg(close[1], open[1]) > 0.012
<...>
else if long == 'long_continuation' and (close[1]-(math.avg(close[1], open[1]))/(math.avg(close[1], open[1]) < 0.012
// Three opening brackets, two closing brackets
else if short == 'short_continuation' and ((math.avg(close[1], open[1])-close[1])/close[1] > 0.012
<...>
else if short == 'short_continuation' and ((math.avg(close[1], open[1])-close[1])/close[1] < 0.012

修复这些问题,代码应该可以正确编译。

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):

// Five opening brackets, three closing brackets
else if long == 'long_continuation' and (close[1]-(math.avg(close[1], open[1]))/(math.avg(close[1], open[1]) > 0.012
<...>
else if long == 'long_continuation' and (close[1]-(math.avg(close[1], open[1]))/(math.avg(close[1], open[1]) < 0.012
// Three opening brackets, two closing brackets
else if short == 'short_continuation' and ((math.avg(close[1], open[1])-close[1])/close[1] > 0.012
<...>
else if short == 'short_continuation' and ((math.avg(close[1], open[1])-close[1])/close[1] < 0.012

Fix these and the code should compile properly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文