English 中文(简体)
为什么用文字计算错误?
原标题:Why is the script calculating wrong?

我写了一个文字,比较了两种符号之间百分比差异的演变,但我可以说明为什么计算错误。

页: 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),而由于相互交织,这一差异只有在造成最终结果与现实之间重大差异时才变得更加明显。

错误在哪里? 事先感谢您的帮助

问题回答

我通过四舍五入1和2数值解决问题,然后根据这些四舍五入的数值进行计算。





相关问题
I m trying to write pinescript to locate side by side candles

Brother candles as per image so the candles open and close values are about the same one bullish, one bearish eg. close of candle 1 = open candle 2 open candles 2 = close candle 1 hope someone may ...

Using if statement when input is selected in pinescript

I have a drop down menu via inputs that should control the backgroundcolor when changed. As a simple example, when I select the 200/200 from the drop down list, I want the background color to use the ...

为什么用文字计算错误?

我写了一个文字,比较了两种符号之间百分比差异的演变,但我可以说明为什么计算错误。

热门标签