请帮我确认一下我对以下实现卡尔曼滤波的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
nz()
将用给定的值替换na
的值。
nz(kf[1], x)
将检查kf[1]
(前一栏中kf
的值)是否为na
。如果是na
,则将其替换为x
。