Pine script 蜡烛关闭后,值返回0

Pine script 蜡烛关闭后,值返回0,pine-script,Pine Script,我正试图绘制从上一天接近当前价格的百分比变化。一切正常,但当新蜡烛关闭时,该值将返回到0,并且仅绘制当前条变化,而不是每日变化。如果我刷新页面,它就会恢复正常,直到另一支蜡烛熄灭 study("Percent change from daily", precision=2) a = input(title="Symbol", type=input.symbol, defval="ftx:btcperp") b = input(title

我正试图绘制从上一天接近当前价格的百分比变化。一切正常,但当新蜡烛关闭时,该值将返回到0,并且仅绘制当前条变化,而不是每日变化。如果我刷新页面,它就会恢复正常,直到另一支蜡烛熄灭

study("Percent change from daily", precision=2)
a = input(title="Symbol", type=input.symbol, defval="ftx:btcperp")
b = input(title="Resolution", type=input.resolution, defval="D")
c = security(a, b, close)
d = (close - c[1]) / c[1] * 100
plot(d)

这将计算图表的
close
和通过
security()
调用获取的非重新绘制HTF值之间的ROC,这是symbol
a
的最后一个完成日的结束时间:

//@version=4
study("Percent change from daily", precision=2)
a = input(title="Symbol", type=input.symbol, defval="ftx:btcperp")
b = input(title="Resolution", type=input.resolution, defval="D")

f_security(_sym, _res, _src, _rep) => security(_sym, _res, _src[not _rep and barstate.isrealtime ? 1 : 0])[_rep or barstate.isrealtime ? 0 : 1]
// Non-repainting HTF value.
c = f_security(a, b, close, false)
d = (close - c) / c * 100
plot(d)