aref razavi
aref razavi

Reputation: 422

pine script how to convert Fractal indicator from v2 to v4

this is a open source indicator called "Fractal Support Resistance".

//@version=2
//synapticex.com
study("Fractal Support Resistance", shorttitle="FSR", overlay=true)
tf = input(title="Resolution", type=resolution, defval = "current")
vamp = input(title="VolumeMA", type=integer, defval=6)
vam = sma(volume, vamp)

up = high[3]>high[4] and high[4]>high[5] and high[2]<high[3] and high[1]<high[2] and volume[3]>vam[3]
down = low[3]<low[4] and low[4]<low[5] and low[2]>low[3] and low[1]>low[2] and volume[3]>vam[3]
fractalup =  up ? high[3] : fractalup[1] 
fractaldown = down ? low[3] : fractaldown[1]

fuptf = security(tickerid,tf == "current" ? period : tf, fractalup)
fdowntf = security(tickerid,tf == "current" ? period : tf, fractaldown)

plot(fuptf, "FractalUp", color=lime, linewidth=1, style=cross, transp=0, offset =-3, join=false)
plot(fdowntf, "FractalDown", color=red, linewidth=1, style=cross, transp=0, offset=-3, join=false)

have you any idea to convert that to version 4 ? I change it to this:

//@version=4
study("Fractal Support Resistance", shorttitle="FSR", overlay=true)
tf = input("current" , type = input.resolution )
vamp = input(6, type = input.integer)
vam = sma(volume, vamp)

up = high[3]>high[4] and high[4]>high[5] and high[2]<high[3] and high[1]<high[2] and volume[3]>vam[3]
down = low[3]<low[4] and low[4]<low[5] and low[2]>low[3] and low[1]>low[2] and volume[3]>vam[3]
fractalup =  up ? high[3] : fractalup[1] 
fractaldown = down ? low[3] : fractaldown[1]

fuptf = security(tickerid,tf == "current" ? period : tf, fractalup)
fdowntf = security(tickerid,tf == "current" ? period : tf, fractaldown)

plot(fuptf, "FractalUp", color=lime, linewidth=1, style=cross, transp=0, offset =-3, join=false)
plot(fdowntf, "FractalDown", color=red, linewidth=1, style=cross, transp=0, offset=-3, join=false)

and it give me this errors:

line 12: Undeclared identifier 'fractalup';
line 13: Undeclared identifier 'fractaldown';
line 15: Undeclared identifier 'tickerid';
line 15: Undeclared identifier 'period';
line 15: Undeclared identifier 'fractalup';
line 16: Undeclared identifier 'tickerid';
line 16: Undeclared identifier 'period';
line 16: Undeclared identifier 'fractaldown';
line 18: Undeclared identifier 'fuptf';
line 18: Undeclared identifier 'lime';
line 18: Undeclared identifier 'cross';
line 19: Undeclared identifier 'fdowntf';
line 19: Undeclared identifier 'red';
line 19: Undeclared identifier 'cross'

is there a default value for identifier in v2 that does not exist in v4 ? if yes what is that default value ?

Upvotes: 0

Views: 144

Answers (1)

vitruvius
vitruvius

Reputation: 21199

Self referencing is not allowed anymore.

So, statements like below are invalid:

fractalup =  up ? high[3] : fractalup[1] 

You need to first declare the variable and then use the := assignment operator on it:

fractalup = 0.0
fractalup := up ? high[3] : fractalup[1] 

Check out the migration guides for more information. After you convert it to v3, you can use the auto converter tool.

Upvotes: 1

Related Questions