pine在循环的第一行上引发语法错误

发布于 2025-02-09 17:27:26 字数 887 浏览 1 评论 0原文

我有一种松树策略:

//@version=5
strategy("Elie's strategy", overlay=true, margin_long=100, margin_short=100)

var float[] overSRLs = na
var IDCounter = 0
int[] removeFromOver = na

for int i = 0 to (array.size(overSRLs) - 1) // line 8
    if low < array.get(overSRLs, i)
        orderID = str.tostring(IDCounter)
        exitID = str.tostring(IDCounter + 1)
        IDCounter += 2
        strategy.order(orderID, strategy.long, 1)
        strategy.exit(exitID, from_entry=orderID, stop = (array.get(overSRLs, i) * (1 - ATR5[1])), limit = (array.get(overSRLs, i) * (1 + ATR5[1]))
        array.push(removeFromOver, i)

我知道这不是一项策略,但是我切掉了无关紧要的部分,以制作一个较小的可生殖典范。当仅保存上面的代码时,它会引发以下错误:

line 8: Syntax error at input 'int'.

现在,即使第8行是的的初始化,我认为问题在 ,编译器/解释器的错误处理不好。我在这里缺少什么吗?一切对我来说都很好

I have a pine strategy:

//@version=5
strategy("Elie's strategy", overlay=true, margin_long=100, margin_short=100)

var float[] overSRLs = na
var IDCounter = 0
int[] removeFromOver = na

for int i = 0 to (array.size(overSRLs) - 1) // line 8
    if low < array.get(overSRLs, i)
        orderID = str.tostring(IDCounter)
        exitID = str.tostring(IDCounter + 1)
        IDCounter += 2
        strategy.order(orderID, strategy.long, 1)
        strategy.exit(exitID, from_entry=orderID, stop = (array.get(overSRLs, i) * (1 - ATR5[1])), limit = (array.get(overSRLs, i) * (1 + ATR5[1]))
        array.push(removeFromOver, i)

I know it's not much of a strategy, but I cut out the irrelevant parts to make a smaller reproductible example. When just the code above is saved, it throws the following error:

line 8: Syntax error at input 'int'.

Now, even though line 8 is the init of the for, I think the problem is in the code block in the for, and the compiler/interpreter just has bad error handling. Is there something I'm missing here? Everything looks fine to me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

感情洁癖 2025-02-16 17:27:26

我认为问题在for中的代码块中,并且编译器/解释器的错误处理不好。

是的,问题是在strateger.exit中 - 最终需要一个额外的闭合括号。编译器并不总是为循环中的错误提供正确的行。评论循环并将所有内容移动到左侧,您会发现新错误是第14行:输入处的语法错误'('。,这表明 它找不到它的一对)。

打开括号(因为 可读性。

I think the problem is in the code block in the for, and the compiler/interpreter just has bad error handling.

Yes, the issue is in the strategy.exit -- you need one extra closing bracket in the end there. Compiler does not always provide correct lines for errors in loops. Comment out the loop and move everything one tab to the left and you'll see that the new error is line 14: Syntax error at input '('., which indicates that there is an issue with the opening bracket (because it can't find its pair).

P.S. The script will not compile after that because of the undeclared ATR5 variable, but I assume it's due to the fact that you trimmed the example code for readability.

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