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

Pine Script代码报错:Error at 15:19 no viable alternative at character ';' 求解决

问题解决:Pine Script 语法错误 "no viable alternative at character ';'"

错误原因

  1. 分号多余:Pine Script 不需要用分号作为语句结束标记,代码中每行末尾的分号属于无效语法,触发编译器报错。
  2. input 声明语法错误:在 Pine Script 中,input 是函数而非关键字,不能直接用 input 变量名 = 值 的形式声明输入变量。

修正后的代码

strategy("My script", overlay = true)

// 用正确的 input 函数语法声明输入变量
highSource = input(close, title="High Source")
lowSource = input(close, title="Low Source")
period = input.int(20, title="Period")
standardDeviation = input.float(2.0, title="Standard Deviation")

关键说明

  • 移除了所有语句末尾的分号。
  • 使用类型匹配的 input 函数:input.int() 用于整数参数,input.float() 用于浮点参数,通用 input() 可用于价格序列;通过 title 参数添加显示名称,方便在图表设置中调整参数。
  • 若需让用户切换价格数据源,可将默认值 close 替换为 high/low/open 等内置变量。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 23:27:17