了解此代码中的Pinescript NZ函数用法
请帮助我确认我对实现Kalman过滤器的以下Pinescript功能的理解。我在代码中包括了一些评论,我对代码要完成的内容进行了理解/问题。谢谢!
kalman(x, g) =>
//x is a moving average (MA) and g is a constant
kf = 0.0
dk = x - nz(kf[1], x) //Calculate the difference between current bar's MA value and
//MA value at the previous bar?
smooth = nz(kf[1], x) + dk * math.sqrt(g * 2) //Is nz(kf[1], x) equal to the previous
//bar's MA value?
velo = 0.0
velo := nz(velo[1], 0) + g * dk //Not sure what nz(velo[1], 0) is supposed to model.
//Is that building velo by adding velo's value on the
//previous bar to g*dk?
kf := smooth + velo
Please help me confirm my understanding of the following Pinescript function which implements a Kalman filter. I have included some comments in the code with my understanding/questions on what the code is trying to accomplish. Thanks!
kalman(x, g) =>
//x is a moving average (MA) and g is a constant
kf = 0.0
dk = x - nz(kf[1], x) //Calculate the difference between current bar's MA value and
//MA value at the previous bar?
smooth = nz(kf[1], x) + dk * math.sqrt(g * 2) //Is nz(kf[1], x) equal to the previous
//bar's MA value?
velo = 0.0
velo := nz(velo[1], 0) + g * dk //Not sure what nz(velo[1], 0) is supposed to model.
//Is that building velo by adding velo's value on the
//previous bar to g*dk?
kf := smooth + velo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
nz()
将用给定值替换Na
值。nz(kf [1],x)
将检查kf [1]
(kf
在上一个bar上的值)为na
。如果是NA
,它将用X
替换它。nz()
will replacena
values with the given value.nz(kf[1], x)
will check ifkf[1]
(kf
's value on the previous bar) isna
. If it isna
, it will replace it withx
.