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

Pine Script报simple string expected错:调用request.security如何传字符串数组元素

问题原因

Pine Script中request.security()函数的symbol参数要求为simple string类型,也就是编译阶段就能确定值的常量字符串。你通过array.get()从数组中取出的ticker属于series string类型,只有脚本运行时才能拿到具体值,不符合参数类型要求,因此触发报错。

可行解决方法

Pine Script目前不支持运行时动态生成symbol参数调用request.security(),所有传入的symbol必须在编译时就确定,你可以根据自己的使用场景选择以下两种方案:

  • 方案1:硬编码逐个调用(适用于标的数量固定且较少的场景,性能最稳定)
//@version=5
indicator("多标的同周期数据拉取", overlay=false)
period = timeframe.period

// 逐个请求固定标的数据
fb_series = request.security("FB", period, close)
aapl_series = request.security("AAPL", period, close)
tsla_series = request.security("TSLA", period, close)
msft_series = request.security("MSFT", period, close)
amzn_series = request.security("AMZN", period, close)
nflx_series = request.security("NFLX", period, close)
goog_series = request.security("GOOG", period, close)
nvda_series = request.security("NVDA", period, close)

// 逐个绘制曲线
plot(fb_series, color=color.red, title="FB")
plot(aapl_series, color=color.green, title="AAPL")
plot(tsla_series, color=color.blue, title="TSLA")
plot(msft_series, color=color.orange, title="MSFT")
plot(amzn_series, color=color.purple, title="AMZN")
plot(nflx_series, color=color.yellow, title="NFLX")
plot(goog_series, color=color.gray, title="GOOG")
plot(nvda_series, color=color.teal, title="NVDA")
  • 方案2:使用input.symbol_list定义可编辑标的列表(适用于需要灵活调整标的的场景,同样在编译期确定所有symbol值)
//@version=5
indicator("多标的自定义拉取", overlay=false)
period = timeframe.period
// 定义可在设置界面编辑的标的列表,编译阶段就会确定所有值
symbol_list = input.symbol_list("FB,AAPL,TSLA,MSFT,AMZN,NFLX,GOOG,NVDA", title="标的列表")
// 按索引逐个拉取并绘制
plot(request.security(symbol_list.get(0), period, close), title=symbol_list.get(0))
plot(request.security(symbol_list.get(1), period, close), title=symbol_list.get(1))
plot(request.security(symbol_list.get(2), period, close), title=symbol_list.get(2))
plot(request.security(symbol_list.get(3), period, close), title=symbol_list.get(3))
plot(request.security(symbol_list.get(4), period, close), title=symbol_list.get(4))
plot(request.security(symbol_list.get(5), period, close), title=symbol_list.get(5))
plot(request.security(symbol_list.get(6), period, close), title=symbol_list.get(6))
plot(request.security(symbol_list.get(7), period, close), title=symbol_list.get(7))

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.23 15:45:00