Pine Script 5中if语句报错:输入不匹配'=',期望无续行结束符
Pine Script 5 报错 "Mismatched input '=' expecting 'end of line without line continuation'" 解决方案
你的代码存在两个语法问题,直接导致了这个报错:
判断条件误用赋值运算符
Pine Script 里=是赋值符号,用于给变量赋值;而判断相等需要用==。不过因为longCondition和shortCondition本身就是布尔类型变量,你可以直接把变量作为if的判断条件,不需要额外的比较操作,写法更简洁。if语句末尾多余的逗号
代码里if longCondition=true,的逗号是无效语法,Pine Script不允许这种写法,直接去掉即可。
修正后的代码如下:
longCondition = ta.crossover(close, usdt_rsmi) shortCondition = ta.crossunder(close, usdt_rsmi) if longCondition strategy.entry("Enter Long", strategy.long) if shortCondition strategy.entry("Enter Short", strategy.short)
如果坚持使用比较运算符,也可以写成:
longCondition = ta.crossover(close, usdt_rsmi) shortCondition = ta.crossunder(close, usdt_rsmi) if longCondition == true strategy.entry("Enter Long", strategy.long) if shortCondition == true strategy.entry("Enter Short", strategy.short)
内容的提问来源于stack exchange,提问作者wolfskyknight
相关产品推荐
相关产品推荐

