pine-script - 我在 Pine Script 中遇到 TradingView 的 'end of line without continuation' 错误

标签 pine-script

我在 Pine Script 中使用此代码,但收到“不匹配的输入 'a' 期望'行尾没有行继续'”错误。

如何使用此功能代码修复该错误?

val(s) =>
     if s != s[1] 
     a = s-s[1]
     if s = s[1]
     a
    a

最佳答案

'end of line without continuation' error当 TradingView Pine 代码中出现缩进错误时会发生这种情况。

查看您的代码(并假设将其复制到 StackOverflow 中是正确的),确实存在缩进问题:

val(s) =>
     if s != s[1] 
     a = s-s[1]
     if s = s[1]
     a
    a

这段代码有两个缩进问题:
  • 函数的前 4 行缩进 5 个空格(或 1 个 Tab 加一个空格)。但是函数的代码行需要在 TradingView Pine 中缩进 4 个空格(或 1 个 Tab)。
  • if 语句之后的两行不缩进。但它们确实需要:有 4 个空格(或 1 个 Tab)或其倍数。

  • 当我们修复这两点时,代码变为:
    val(s) =>
        if s != s[1] 
            a = s-s[1]
        if s == s[1]
            a
        a
    

    (请注意,我还在此处用 = 运算符替换了 == 赋值运算符以实现相等性。)

    上面的代码也触发了'undeclared identifier' error因为a变量:它在您的函数中声明之前使用。我不确定您是否也想要修复,或者您发布的功能代码只是更大功能的一部分。

    但是,如果您还想修复那个“未声明的标识符”错误,您可以将函数代码更改为:
    val(s) =>
        a = 0.0
        if s != s[1] 
            a := s-s[1]
        if s == s[1]
            a
        a
    

    关于pine-script - 我在 Pine Script 中遇到 TradingView 的 'end of line without continuation' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51724359/

    相关文章:

    pine-script - 在绘图上使用样式变量

    plot - 如何在交易 View 的 PINE 图中使用不同的字符串文字?

    conditional-statements - 当条件从 true/false 改变时的警报条件之后。如果任一条件为真,当前会发出警报。不是在它改变的时候

    pine-script - 为单次入场设置多个止损离场订单

    pine-script - 如何获得前一天的最后一支蜡烛?

    pine-script - TradingView – Pine Script 中单个订单的多个止盈

    time - TradingView Pine 脚本的周末 time() 函数?

    pine-script - Pine-Script 自引用变量的问题

    error-handling - 松脚本: “Can' t call 'security' inside: 'if' , 'for' ”

    pine-script - 有没有办法在 tradingview pine 脚本中检测图表背景颜色?