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

PineScript绘制支撑阻力位报错:输入'['处语法错误

解决PineScript v5支撑阻力位定义的语法错误

错误核心原因

PineScript v5不支持直接用[]语法初始化数组,这是触发“输入'['处语法错误”的关键——哪怕用常量值,[xxx, xxx]的写法也不符合PineScript的语法规范。

正确实现代码

以下是可正常运行的支撑阻力位绘制代码,使用官方提供的数组构造函数定义点位:

//@version=5
indicator("自定义支撑阻力位", overlay=true)

// 用array.from()从常量值直接创建支撑/阻力位数组
support_levels = array.from(1800.0, 1750.0, 1700.0)
resistance_levels = array.from(1900.0, 1950.0, 2000.0)

// 遍历支撑位数组,绘制绿色虚线
for level in support_levels
    hline(level, "支撑位 " + str.tostring(level), color=color.new(color.green, 0), linestyle=hline.style_dashed)

// 遍历阻力位数组,绘制红色虚线
for level in resistance_levels
    hline(level, "阻力位 " + str.tostring(level), color=color.new(color.red, 0), linestyle=hline.style_dashed)

动态点位的可选写法

如果需要后续动态添加点位(比如计算导入或实时生成),可以先创建空数组再逐个添加元素:

// 创建空的浮点数数组
support_levels = array.new_float()
// 逐个添加支撑位
array.push(support_levels, 1800.0)
array.push(support_levels, 1750.0)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 22:32:44