了解此代码中的Pinescript NZ函数用法

发布于 2025-01-26 11:10:14 字数 777 浏览 3 评论 0原文

请帮助我确认我对实现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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不寐倦长更 2025-02-02 11:10:14

nz()将用给定值替换Na值。

nz(kf [1],x)将检查kf [1]kf在上一个bar上的值)为na。如果是NA,它将用X替换它。

nz() will replace na values with the given value.

nz(kf[1], x) will check if kf[1] (kf's value on the previous bar) is na. If it is na, it will replace it with x.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文