咨询:出现“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
相关产品推荐
相关产品推荐

