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

PineScript编译错误求助:第10行多余输入':',新手求排查

Pine Script编译错误修复方案

核心错误点

  • Pine Script的if语句结尾不需要加冒号:,这是Python类语言的语法,Pine Script不支持,这是触发第10行编译错误的直接原因。
  • 代码中使用了HTML转义字符&lt;/&gt;,需替换为实际的</>;Pine Script v5推荐用//作为单行注释,而非#。

修复后的完整代码

//@version=5
strategy("RSI Divergence Strategy", overlay=true)

// Define the RSI period
period = 14

// Calculate the RSI
rsi = ta.rsi(close, period)

// Check for bullish divergence
if (rsi < 30) and (rsi < rsi[1]) and (close > close[1])
    // Bullish divergence detected, go long
    strategy.entry("Long", strategy.long)
    strategy.exit("Exit long", "Long", profit=50, stop=-50)

// Check for bearish divergence
if (rsi > 70) and (rsi > rsi[1]) and (close < close[1])
    // Bearish divergence detected, go short
    strategy.entry("Short", strategy.short)
    strategy.exit("Exit short", "Short", profit=50, stop=-50)

额外优化说明

  • 补充了strategy()声明,这是Pine Script v5策略脚本的必填项,缺失会导致运行报错。
  • 将long=true/short=true替换为更规范的strategy.long/strategy.short,符合v5语法习惯。
  • 统一使用//做单行注释,保持代码风格一致性。

内容的提问来源于stack exchange,提问作者Official Jayo

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 06:50:32