代码之家  ›  专栏  ›  技术社区  ›  Nesar Hemmat

输入“没有换行符的行尾”处出现语法错误,Pine Script,TradingView

  •  0
  • Nesar Hemmat  · 技术社区  · 1 年前
    //@version=5
    // Display correlation matrix with labels
    var label corr_matrix = label.new(x=na, y=na, text="", style=label.style_label_down, size=size.normal, color=color.white)
    maxBarIndex = ta.highest(bar_index, 1)
    if (bar_index == maxBarIndex)
        label.set_xy(corr_matrix, bar_index, high)
        label.set_text(corr_matrix,
            "Corr 1-2: " + str.tostring(correlation_1_2, format.percent) + "\n" +
            "Corr 1-3: " + str.tostring(correlation_1_3, format.percent) + "\n" +
            "Corr 1-4: " + str.tostring(correlation_1_4, format.percent) + "\n" +
            "Corr 2-3: " + str.tostring(correlation_2_3, format.percent) + "\n" +
            "Corr 2-4: " + str.tostring(correlation_2_4, format.percent) + "\n" +
            "Corr 3-4: " + str.tostring(correlation_3_4, format.percent)
        )
    

    在代码的第46行“label.set_text(corr_matrix)”中,它在输入“行尾无换行符”时给了我一个语法错误。缩进在我看来并没有错,这就是为什么我真的不确定问题的根源。这让我很困惑,有什么办法解决这个问题吗?

    1 回复  |  直到 1 年前
        1
  •  0
  •   vitruvius    1 年前

    换行时,新行必须以一个或多个(不同于4的多个)空格开头。

    if (bar_index == maxBarIndex)
        label.set_xy(corr_matrix, bar_index, high)
        label.set_text(corr_matrix,
             "Corr 1-2: " + str.tostring(correlation_1_2, format.percent) + "\n" +
             "Corr 1-3: " + str.tostring(correlation_1_3, format.percent) + "\n" +
             "Corr 1-4: " + str.tostring(correlation_1_4, format.percent) + "\n" +
             "Corr 2-3: " + str.tostring(correlation_2_3, format.percent) + "\n" +
             "Corr 2-4: " + str.tostring(correlation_2_4, format.percent) + "\n" +
             "Corr 3-4: " + str.tostring(correlation_3_4, format.percent)
         )
    
        2
  •  0
  •   Nesar Hemmat    1 年前

    谢谢你,它现在可以工作了,我不知道松木脚本的缩进是如何工作的,因为这是我第一次遇到它

    推荐文章