You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pine Script 5中if语句报错:输入不匹配'=',期望无续行结束符

Pine Script 5 报错 "Mismatched input '=' expecting 'end of line without line continuation'" 解决方案

你的代码存在两个语法问题,直接导致了这个报错:

  1. 判断条件误用赋值运算符
    Pine Script 里=是赋值符号,用于给变量赋值;而判断相等需要用==。不过因为longCondition和shortCondition本身就是布尔类型变量,你可以直接把变量作为if的判断条件,不需要额外的比较操作,写法更简洁。

  2. 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 06:15:43