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

Pine Script语法错误求助:数组定义引发的两类语法报错

Pine Script 语法错误排查与解决

第一个错误:Error at 5:18 Syntax error at input '['

Pine Script v5不支持直接通过[[]]字面量定义二维数组,必须使用官方提供的数组构造函数来创建嵌套数组结构,你最初的写法不符合Pine的数组语法规范。

第二个错误:Error at 5:25 Syntax error at input 'end of line without line continuation'

你尝试用array([[]])包裹字面量数组的写法是错误的,Pine中没有这种数组初始化方式,且换行时缺少正确的语法支持。同时二维数组的创建需要分步完成,不能一次性嵌套字面量。

修正后的完整代码

//@version=5
indicator("Vertical Line Indicator", overlay=true)

// 构建品种与对应日期的二维数组
symbolDateList = array.new_array()
// 逐个添加品种和目标时间
array.push(symbolDateList, array.from("MVIS", timestamp("2023-06-01 00:00")))
array.push(symbolDateList, array.from("XAUUSD", timestamp("2023-06-03 00:00")))

// 遍历数组,匹配当前品种与时间后绘制竖线
for i = 0 to array.size(symbolDateList) - 1
    currentPair = array.get(symbolDateList, i)
    targetSymbol = array.get(currentPair, 0)
    targetTime = array.get(currentPair, 1)
    // 使用ticker.symbol匹配品种代码(不含交易所前缀,与你定义的格式一致)
    if ticker.symbol == targetSymbol and time == targetTime
        line.new(bar_index, low, bar_index, high, color=color.rgb(0, 191, 255), width=2, style=line.style_solid)

关键说明

  1. 数组创建方式:用array.new_array()创建外层数组,通过array.from()生成每个包含品种和时间的内层数组,再用array.push()添加到外层数组中,这是Pine v5中创建二维数组的标准方式。
  2. 品种匹配:替换syminfo.tickerid为ticker.symbol,因为syminfo.tickerid会包含交易所前缀(如NASDAQ:MVIS),而你定义的是纯品种代码,用ticker.symbol能精准匹配。
  3. 遍历逻辑:通过索引遍历数组,确保能正确获取每个内层数组的元素。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 19:37:32