how to check if pair exist in security function?

走远了吗. 提交于 2021-01-28 06:03:30

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/60126119/how-to-check-if-pair-exist-in-security-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!