Reputation: 11
I am trying to convert the following function into 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])
But, it returns with an error:
Cannot modify global variable 'filt' in function
Upvotes: 1
Views: 189
Reputation: 6915
Your function should be like this
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])
and then in your main code, you should use your function to assign the result to filt
, like this:
filt := ssFilter(price, lowerBand)
Upvotes: 1