rohan sawant
rohan sawant

Reputation: 121

Cannot get a 'ticker' of a spread symbol Trading View

When a spread symbol comes like NSE:BANKNIFTY1!/NSE:NIFTY1! the system should use standard open, high, low and close

In other cases it should use the mentioned close as per code.

I am using syminfo.prefix+":"+syminfo.ticker and not syminfo.tickerid, because i want candlestick open, high, low and close; when i change to HA, Renko, Kagi, Line, Point & Figure.

But despite the code being accurate, I get an error.

How do I fix this? I have tried everything

//@version=4
study("spread", overlay=true)


var float close_lock    = na
var float open_lock     = na
var float high_lock     = na
var float low_lock      = na

var bool normal_ticker_check    = na
normal_ticker_check := syminfo.type != 'spread'

[o, h, l, c] = security(syminfo.prefix+":"+syminfo.ticker , timeframe.period , [open, high, low, close] ,barmerge.gaps_off, barmerge.lookahead_on) 

if (normal_ticker_check)
    close_lock   := c
    open_lock    := o
    high_lock    := h
    low_lock     := l
else
    close_lock   := close 
    open_lock    := open 
    high_lock    := high 
    low_lock     := low 
    
    
plot(close_lock)

ERROR: Cannot get a 'ticker' of a spread symbol

Upvotes: 0

Views: 817

Answers (1)

Bjorgum
Bjorgum

Reputation: 2310

syminfo.type definition from manual:

Type of the current symbol. Possible values are stock, futures, index, forex, crypto, fund, dr.

so it appears that the string 'spread' cannot be detected with that check, but replacing your security call with the following should get you past the error:

[o, h, l, c] = security(syminfo.tickerid, timeframe.period , [open, high, low, close] ,barmerge.gaps_off, barmerge.lookahead_on)

Upvotes: 0

Related Questions