如何检查安全功能中是否存在配对? [英] how to check if pair exist in security function?

查看:45
本文介绍了如何检查安全功能中是否存在配对?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本可以检查特定条件下的多个对.但是,现在一对 (BINANCE:BTGETH) 不再存在,它破坏了我的脚本:你得到一个错误,不再有价值.

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.

如果对确实存在,我想在我的脚本内部检查,这样我的脚本将继续运行,尽管其中一个对不再可用.就像,在 Java 中,try-catch 或其他东西.

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.

我试过在 security/input 函数上做 if-then ,或者在它上面使用 na() ,但这确实不行.例如.类似的东西:

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)

对此有什么想法吗?我知道 pinescript 不擅长处理这些事情,我希望有一些东西可以解决这个问题.

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)

这会绘图,但只要符号不存在,它就会编译,但您会收到 invalid_symbol 警告并且脚本会中断.

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.

推荐答案

不幸的是,这是不可能的.这不是 pine-script 本身的限制,而是交易视图如何运行研究(包括内置的)的方式:研究需要大量的交易品种(一个或多个),并且只有当所有交易品种都准备好时,计算将启动.因此,如果系统检测到所需交易品种之一不存在或因任何原因无法询问(例如该交易品种没有日内交易,但一项研究需要该交易品种的日内决议),那么该研究甚至将被拒绝没有开始任何逻辑.因此,在tradingview 更改该工作流程之前,pine 将无法支持您在此处想要的行为.

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.

这篇关于如何检查安全功能中是否存在配对?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆