crypturtle
Pine Script Rookie
Pine Script Rookie
Posts: 3
Joined: January 27th, 2022
Contact: TradingView Profile

Convert pine script old version to version 5

Hello,

I recently start to learn Pine code few weeks ago (huge thanks to Mathew for the fantastic tutorial !!!).
I am trying to convert an old code I found from #madrid into version 5

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 I get the following error:
Add to Chart operation failed, reason: line 26: Undeclared identifier `filt`

so I have try the following thing:

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

filt := ssFilter(close, lowerBand)

but I still have the same error:
line 25: Undeclared identifier `filt`

if anyone know how to fix it your help will be greatly appreciated! :zen:

processingclouds
Pine Script Master
Pine Script Master
Posts: 115
Joined: January 30th, 2022

Re: Convert pine script old version to version 5

Hey crypturtle,

Your last line :
filt = c1*(price + nz(price[1]))/2 + c2*nz(filt[1]) + c3*nz(filt[2])
OR
c1*(close + nz(close[1]))/2 + c2*nz(filt[1]) + c3*nz(filt[2])

It has the variable filt already being used. So technically you are trying to reference filt within filt without it being initialized in anyways.

processingclouds
Pine Script Master
Pine Script Master
Posts: 115
Joined: January 30th, 2022

Re: Convert pine script old version to version 5

A way to solve this is to add filt = 0 before hand.
Also to convert to version 5 , we add math. to each function making it math.sqrt , math.pi and math.cos

Code: Select all

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © processingclouds

//@version=5
indicator("My script")

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

plot(na)
I hope this helps. If you need complete code conversion, i can help you convert it to v5.

crypturtle
Pine Script Rookie
Pine Script Rookie
Posts: 3
Joined: January 27th, 2022
Contact: TradingView Profile

Re: Convert pine script old version to version 5

Thank you very very very much processingclouds! its finally working.
I had try to declare filt=0.0 outside, just before the ssfilter function and it wasn't working.

anyway, thank you again.

processingclouds
Pine Script Master
Pine Script Master
Posts: 115
Joined: January 30th, 2022

Re: Convert pine script old version to version 5

Welcome , if you have any more questions , just drop a post .

Return to “Pine Script Q&A”