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

咨询:出现“stopValue输入不匹配,期望无续行的行尾”错误的原因

Pine Script报错:输入‘stopValue’不匹配,期望‘无续行的行尾’问题解答

这个错误不是缩进问题,根源是你违反了Pine Script的语法规则:

错误原因

Pine Script是大小写敏感的语言,条件判断的关键字必须是小写的if,但你代码第9行写的是大写的If——这会被识别成普通变量名,而非条件判断关键字,直接打乱了后续代码的语法结构,才会触发第11行的匹配错误。

修正后的代码

strategy("Reailing Stop", overlay = true)
if close > ta.sma(close, 50)
    strategy.entry("long", strategy.long)

// 追踪止损
Trailperc = 0.2
price_stop = 0.0

if (strategy.position_size > 0)
    stopValue = close * (1 - Trailperc)
    price_stop := math.max(stopValue, price_stop[1])
else
    price_stop := 0
if (strategy.position_size > 0)
    strategy.exit(id= "Stop Loss", stop= price_stop)

额外提示

  • 写Pine Script时要严格区分关键字的大小写,所有内置关键字(比如if、strategy、math等)都必须小写。
  • 你的代码缩进是正确的,不需要调整。

内容的提问来源于stack exchange,提问作者Jonathan Calleja

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 03:50:26