Conversion to pinescript v4



我正在尝试将以下函数转换为pinescript v4.0:

ssFilter( price, lowerBand ) =>
angle = sqrt(2)*PI/lowerBand
a1= exp(-angle)
b1 = 2*a1*cos(angle)
c2 = b1
c3 = -a1*a1
c1 = 1 - c2 -c3
filt := c1*(price + nz(price[1]))/2 + c2*nz(filt[1]) + c3*nz(filt[2])

但是,它返回时出现错误:

无法修改函数中的全局变量'filt'

您的函数应该是这样的

ssFilter(price, lowerBand) =>
angle = sqrt(2)*PI/lowerBand
a1= exp(-angle)
b1 = 2*a1*cos(angle)
c2 = b1
c3 = -a1*a1
c1 = 1 - c2 -c3
c1*(price + nz(price[1]))/2 + c2*nz(filt[1]) + c3*nz(filt[2])

然后在主代码中,您应该使用函数将结果分配给filt,如下所示:

filt := ssFilter(price, lowerBand) 

最新更新