首页 > 解决方案 > 不能用 '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 

标签: pine-scripttradingsecure-trading

解决方案


您不能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)

推荐阅读