pine-script - 不能用 'symbol'=series[string] 调用 'security'。参数的类型应该是:字符串;
问题描述
我该如何解决这个问题?
如果我删除安全功能,我会收到一个新错误。安全表达式中的可变变量。完成了安全功能以摆脱它。但现在我得到了新的错误
错误: 第 31 行:无法使用 'symbol'=series[string] 调用 'security'。 参数的类型应该是:字符串; 第 33 行:未声明的标识符“bs”; 第 34 行:未声明的标识符“crs”
//@version=4
study("CRS 3", shorttitle="CRS 3")
a = syminfo.tickerid
input1 = input("DJI", type=input.symbol)
input2 = input("NIFTY1!", type=input.symbol)
//var string b = na
//if a == "NIFTY1!"
// b := input1
//else
// b := input2
cal_b() =>
var string b = na
if a == "NIFTY1!"
b := input1
else
b := input2
return = b
as = security(a, timeframe.period, close) //LINE 31
bs = security(cal_b(), timeframe.period, close)
crs = as/bs //LINE 33
plot(crs, linewidth=1, color=color.black, title="CRS", display=display.all, transp=0) //LINE 34
解决方案
您不能security()
使用参数的可变变量调用symbol
。
它必须是一个固定值,在脚本执行期间不会改变。
像这样的东西会起作用:
//@version=4
study("CRS 3", shorttitle="CRS 3")
input1 = input("DJI", type=input.symbol)
input2 = input("NIFTY1!", type=input.symbol)
var float bs = na
a = syminfo.ticker
as = security(a, timeframe.period, close)
bs1 = security(input1, timeframe.period, close)
bs2 = security(input2, timeframe.period, close)
if a == "NIFTY1!"
bs := bs1
else
bs := bs2
crs = as/bs
plot(crs, linewidth=1, color=color.black, title="CRS", display=display.all)
推荐阅读
- javascript - Gulp 可以吗?Gulp 更改文本和目标
- python - 不和谐.py | Sqlite 邀请记录器
- mongodb - 将 MERN 应用程序部署到 heroku 时,操作 `users.findOne()` 缓冲在 10000 毫秒后超时
- qgis - 从 QGIS 中的 HERE-api 获取不完整的结果(生成等时线时)
- r - 删除了包含缺失值的 N 行,但没有缺失值或超出范围的值
- reactjs - 未找到 package.json:无法审核没有 package.json 的项目
- teradata - 如何在 teradata 中查找表中的总列数?
- r - 如何用 tidyevaluation 改变变量
- sql - 如何编译包含 if & elsif 语句的程序?
- html - 错误(错误:EPERM:不允许操作,重命名)