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

Pine语言代码报错:未声明标识符,请求排查问题原因

Pine代码未声明标识符错误排查
  • 错误根源:调用sma()函数时缺少数据源参数。Pine Script v3中sma()的语法为sma(source, length),必须指定计算均线的标的数据(比如收盘价close),仅传入周期会导致系统识别到未声明的标识符。
  • 修正后的代码:
// This is a simple moving average cross-over strategy
//@version=3
strategy("Crossover")

// Buy rule
entryLong = crossover(sma(close, 10), sma(close, 20))
if (entryLong)
    strategy.entry("MyLong", strategy.long, qty=1, limit=10, stop=5)

// Sell rule
entryShort = crossunder(sma(close, 10), sma(close, 20))
if entryShort
    strategy.entry("MyShort", strategy.short, qty=1, limit=10, stop=5)
  • 额外提示:代码里limit=10和stop=5是固定价格,实际回测中可能不符合行情逻辑,建议根据价格动态设置(比如close * 1.01这类形式),不过这并非当前错误的诱因。

内容的提问来源于stack exchange,提问作者Sulkhan Metreveli

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 22:25:20