Pine Script编写IF/ELSE IF/ELSE结构报语法错误,请求排查
错误排查与修正
问题根源
你代码里的else if Rtd1 < 0 and Rtd2 < 0)这一行末尾多了一个多余的右括号,这是触发"Mismatched input 'if' expecting 'end of line without line continuation'"错误的直接原因。Pine Script的条件判断语句要求括号完全成对,多余的括号会导致编译器无法正确解析代码结构。
修正后的完整代码
//@version=5 indicator('Automated Label') past_return = input(10, "Old return - Consider return x old candles") more_recent_return = input(5, "Recent return - Consider return x old candles") Rtd1 = (close - close[past_return]) / close[past_return] Rtd2 = (close - close[more_recent_return]) / close[more_recent_return] pre_label = array.new_float(0) if Rtd1 > 0 and Rtd2 > 0 if Rtd1 > Rtd2 array.push(pre_label, value=4) else array.push(pre_label, value=3) else if Rtd2 > 0 array.push(pre_label, value=1) else if Rtd1 < 0 and Rtd2 < 0 if Rtd1 < Rtd2 array.push(pre_label, -4) else array.push(pre_label, -3) else if Rtd2 < 0 array.push(pre_label, -1) else array.push(pre_label,0)
额外提示
你有Python开发经验,但要注意Pine Script的语法细节差异:Pine Script的if条件表达式可以不用括号包裹(包裹也允许),但必须保证括号完全成对,多余或缺失都会触发语法错误。
内容的提问来源于stack exchange,提问作者Gian L
相关产品推荐
相关产品推荐

