Cannot call 'security' with 'symbol'=series[string]. The argument should be of type: string;

2.4k Views Asked by At

HOW DO I SOLVE THIS ISSUE?

IF I remove the security function I get a new error. mutable variable in a security expression. The security function was done to get rid of it. But now I got new errors

ERRORS: line 31: Cannot call 'security' with 'symbol'=series[string]. The argument should be of type: string; line 33: Undeclared identifier 'bs'; line 34: Undeclared identifier '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 

1

There are 1 best solutions below

4
Bjorn Mistiaen On

You cannot call security() with a mutable variable for the symbol parameter.
It must be a fixed value, that does not change during the execution of your script.

Something like this will work:

//@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)