我写了一个文字,比较了两种符号之间百分比差异的演变,但我可以说明为什么计算错误。
页: 1
//@version=4
study(title="Compare", shorttitle="Compare")
rocPeriod = input(1, minval = 1)
Max = input(defval = 5, type = input.float)
Min = input(defval = -5, type = input.float)
showLines = input(true)
showDelta = input(true)
sym1 = input(defval = "BINANCE:BTCUSDT", type = input.symbol)
sym2 = input(defval = "BINANCE:ETHUSDT", type = input.symbol)
perc_change = roc(close, rocPeriod)
res = ""
s1 = security(sym1, res, perc_change)
s2 = security(sym2, res, perc_change)
delta = s1 - s2
var float cumulativeDelta = 0.0
if barstate.isfirst
cumulativeDelta == delta
else
cumulativeDelta := cumulativeDelta + delta
plot(showLines ? s1 : na, "s1", color.orange)
plot(showLines ? s2 : na, "s2", color.blue)
hline(0)
plot(showDelta ? delta : na, "delta", delta > 0 ? color.lime : color.red, 1, plot.style_columns)
plot(cumulativeDelta, title = "CD", color= color.fuchsia)
bgcolor(cumulativeDelta >= Max ? color.red : na, transp=50)
bgcolor(cumulativeDelta <= Min ? color.green : na, transp=50)
首先,事情非常好,文字确定了第一条条条条条,确定了“累积Delta”=“delta”的价值,然后正确进行了第一次计算。 然而,经过几次谈判,“累积汇率”的结果开始出现轻微错误(例如:0.31 + 0.20 =0.52),而由于相互交织,这一差异只有在造成最终结果与现实之间重大差异时才变得更加明显。
错误在哪里? 事先感谢您的帮助