Search code examples
syntax-errorpine-scriptpine-script-v5tradingview-apiend-of-line

Syntax error at input 'end of line without line continuation', Pine Script, TradingView


//@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)
    )

On Line 46 "label.set_text(corr_matrix," of the code it gives me a syntax error at input 'end of line without line continuation'. The indentations don't look wrong to me that's why I'm not really sure where the issue is stemming from. This has me stumped, is there any way to fix this?


Solution

  • When wrapping lines, the new line must begin with one or several (different from multiple of 4) spaces.

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