Pine Script代码出现‘end of line without line continuation’语法错误求助
Pine Script代码出现‘end of line without line continuation’语法错误求助
兄弟,我一眼就瞅出问题在哪了——你在写label.set_text的文本内容时,直接把代码拆成了多行,但Pine Script v5不允许这种无续行符的换行操作,所以才会报这个语法错误。
在Pine Script里,要是想把一行代码拆成多行写,必须在每一行的末尾加上**反斜杠\**作为续行标记,告诉编译器“这行还没完,下一行是延续”。你原来的代码里,每一行字符串拼接的+后面直接换行,编译器就懵了,以为到这行就结束了。另外我还注意到你代码里用了"这种HTML转义的双引号,Pine Script是不识别这个的,得换成正常的双引号"才行。
给你修正后的完整代码:
//@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) \ )
修改说明:
- 给
label.set_text函数的每一行续行处都加了反斜杠\,包括函数参数开头的换行和每一行拼接代码的末尾 - 把所有
"替换成了Pine Script支持的正常双引号"
这样修改后,语法错误应该就消失了,你可以直接复制去测试~
备注:内容来源于stack exchange,提问作者Nesar Hemmat




