Reputation: 31
I have a script which checks multiple pairs for a certain condition. But, now one pair (BINANCE:BTGETH) no longer exists, and it broke my script: you get an error, no value anymore.
I would like to check inside my script if pairs do exist, so my script will keep on running despite one of the pairs no longer being available. Like, in java, try-catch
or something.
I've tried doing if-then
on the security/input
function, or using na()
on it, but that does not work. E.g. stuff like:
ab = na(security("BINANCE:BTGETH", res, low))
ab = iff(na(security("BINANCE:BTGETH", res, low), true)
Any ideas on this? I know pinescript is not good with these kinds of things, I was hoping something exist with which to deal with this.
Other way around it does work, e.g.:
BTGsym = input(title="Symbol", type=symbol, defval="BINANCE:ADAETH")
BTGlow = security(BTGsym, res, low)
ab = na(BTGlow[0])
a := if (ab)
1
else
0
plot(a, color=yellow)
That will plot, but as soon as the symbol does not exist, it will compile but you get an invalid_symbol warning and the script breaks.
Upvotes: 2
Views: 1255
Reputation: 1
You don't need to check.
Alls you need do is determine the value yourself when the pair does not exist by:
sec1 = request.security("BTGUSD", "D", close)
sec2 = request.security("ETHUSD", "D", close)
BTCETH = BTGUSD/ETHUSD
Upvotes: 0
Reputation: 2821
Unfortunately, that is impossible. It's not a restriction of pine-script itself, but the way how studies (included build-in ones) are run by tradingview: a study requests a numerous of symbols (one or more) and only when all the symbols are ready, the calculation will be started. So if the system detects that one of the required symbols doesn't exist or cannot be asked by any reason (e.g. the symbol doesn't have intraday, but a study requires intraday resolution for the symbol), then the study will be rejected even not starting any logic. So till tradingview changed that workflow, pine won't be able to support the behavior you want here.
Upvotes: 1