Pine 脚本中的逆对

Inverse pair in Pine script

我知道 Tradingview 中的 alt+I 逆比例函数。如何在 Pine 脚本中应用反函数,而不是加载,例如在下面的 MWE 中完成的反向对?

//@version=4
study(title="", overlay=false)

timeperiod = "1"

v1 = security("FX_IDC:CADAUD", timeframe.period, close)

lengthFast = input(3,  minval = 0, title = "Fast MA on RSI")
rFast = rsi(v1, lengthFast)
fastMA1  = sma(rFast, lengthFast) 

plot(fastMA, "Fast MA", color=color.red, linewidth=1)

如果您确实需要调用符号本身,可以这样做,但是没有办法验证该符号是否是实际有效的符号。

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

var string ticker = syminfo.prefix + ":" + syminfo.currency + syminfo.basecurrency

inv_close = security(ticker, timeframe.period, close)

plot(inv_close)

否则你可以使用1 / close

例如 AUDCAD,其中 y 等于当前收盘价

1 x 澳元 = y x 加元

(1 x 澳元) / y = (y x 加元) / y

(1 x 澳元) / y = 1 x 加元

= 1 / y

对于倒置蜡烛:

//@version=4
study("Inverse", overlay = false)

o = 1 / open
h = 1 / high
l = 1 / low
c = 1 / close

plotcandle(open = o, high = h, low = l, close = c, title = "Inverse pair", color = c >= o ? color.green : color.red, wickcolor = color.gray)