1

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 

Bjorn Mistiaen
  • 6,459
  • 3
  • 18
  • 42
rohan sawant
  • 121
  • 1
  • 14

1 Answers1

1

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)
Bjorn Mistiaen
  • 6,459
  • 3
  • 18
  • 42
  • The, If Else condition; does not work con first condition when a == "NIFTY1!". This is bypassed. – rohan sawant May 31 '21 at 07:39
  • That's because `syminfo.tickerid` also includes the exchange name: `NSE:NIFTY1!`. If you use `syminfo.ticker` that will have the ticker name without the exchange name: `NIFTY1!`. I've edited my answer and changed `a = syminfo.tickerid` to `a = syminfo.ticker`. That will work. – Bjorn Mistiaen May 31 '21 at 09:14
  • Thank you so much for your genuine efforts. My sincere appreciation and heartfelt gratitude. There seems to be a new issue, it won't work with the previously functions. It seems "a" too has to be used in an, If then condition. If a = nifty, then a=syminfo.tickerid, else a = syminfo.ticker. Can you please help me with code one last time? Again, please accept my deepest thanks. – rohan sawant May 31 '21 at 11:10
  • I have made the if then condition and resolved the issue. Thank you Bjorn Mistiaen – rohan sawant May 31 '21 at 12:10