Wadoline
Pine Script Rookie
Pine Script Rookie
Posts: 1
Joined: April 22nd, 2022

Errors converting Indicator to version 4

Hello,

I'm trying to convert this indicator of Lazybear to version 4. I need to make a strategy but I'm getting a lot of errors. The indicator is called Absolute Strength Index Oscillator

Code: Select all

//@version=4

strategy("ASIO", overlay=true,
     initial_capital=30000,
     commission_type=strategy.commission.cash_per_order,
     commission_value=4)

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Absolute Strength Index Oscillator
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
divisor3= input(true, "--------ASIO--------")
sh=input(false, title="Show as Histo")
lma=input(21, title="EMA Length")
ld=input(34, title="Signal Length")
osl=10 
calc_abssio( ) =>
    A = iff(close>close[1], nz(A[1])+(close/close[1])-1,nz(A[1]))
    M = iff(close==close[1], nz(M[1])+1.0/osl,nz(M[1]))
    D = iff(close<close[1], nz(D[1])+(close[1]/close)-1,nz(D[1]))
    iff (D+M/2==0, 1, 1-1/(1+(A+M/2)/(D+M/2)))


abssi=calc_abssio()
abssio = (abssi - ema(abssi,lma))
alp=2.0/(ld+1)
mt=alp*abssio+(1-alp)*nz(mt[1])
ut=alp*mt+(1-alp)*nz(ut[1])
s=((2-alp)*mt-ut)/(1-alp)
d=abssio-s

plot(not sh ? abssio : na, color=(abssio > 0 ? abssio >= s ? green : orange : abssio <=s ? red :orange), title="ABSSIO", style=histogram, linewidth=2)

The errors that I'm getting are the next:
line 17: Undeclared identifier 'A';
line 18: Undeclared identifier 'M';
line 19: Undeclared identifier 'D';
line 20: Undeclared identifier 'D';
line 20: Undeclared identifier 'M';
line 20: Undeclared identifier 'A';
line 20: Variable 'A' is not found in scope 'calc_abssio', cannot register side effect;
line 20: Variable 'M' is not found in scope 'calc_abssio', cannot register side effect;
line 20: Variable 'D' is not found in scope 'calc_abssio', cannot register side effect;
line 24: Undeclared identifier 'abssi';
line 26: Undeclared identifier 'abssio';
line 26: Undeclared identifier 'mt';
line 27: Undeclared identifier 'mt';
line 27: Undeclared identifier 'ut';
line 28: Undeclared identifier 'mt';
line 28: Undeclared identifier 'ut';
Do you know what am I doing wrong?

Thank you in advance!

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

Re: Errors converting Indicator to version 4

Hey,

You want the lazybear ASIO strategy to be converted to v4.
I have converted the original to v4 and here is working code for ASIO v4:

Code: Select all

// © processingclouds
// Conversion of Absolute Strength Index Oscillator as requested 
// processingclouds For bugs, and to show your support you can contact me anytime here and @gmail
//@version=4

study("Absolute Strength Index Oscillator [LazyBear]", shorttitle="ABSSIO_LB")
sh=input(false, title="Show as Histo")
ebc=input(false, title="Enable Bar Colors")
lma=input(21, title="EMA Length")
ld=input(34, title="Signal Length")
osl=10 
calc_abssio( ) =>
    A = 0.0
    M = 0.0
    D = 0.0
    A:=iff(close>close[1], nz(A[1])+(close/close[1])-1,nz(A[1]))
    M:=iff(close==close[1], nz(M[1])+1.0/osl,nz(M[1]))
    D:=iff(close<close[1], nz(D[1])+(close[1]/close)-1,nz(D[1]))
    iff (D+M/2==0, 1, 1-1/(1+(A+M/2)/(D+M/2)))

abssi=calc_abssio()
abssio = (abssi - ema(abssi,lma))
alp=2.0/(ld+1)
mt = 0.0
ut = 0.0
mt:=alp*abssio+(1-alp)*nz(mt[1])
ut:=alp*mt+(1-alp)*nz(ut[1])
s=((2-alp)*mt-ut)/(1-alp)
d=abssio-s
hline(0, title="ZeroLine")
plot(not sh ? abssio : na, color=(abssio > 0 ? abssio >= s ? color.green : color.orange : abssio <=s ? color.red : color.orange), title="ABSSIO", style=plot.style_histogram, linewidth=2)
plot(not sh ? abssio : na, color=color.black, style=plot.style_line,title="ABSSIO_Points", linewidth=2)
plot(not sh ? s : na, color=color.gray, title="MA")
plot(sh ? d : na, style=plot.style_columns, color=d>0?color.green:color.red)
barcolor(ebc?(abssio > 0 ? abssio >= s ? color.lime : color.orange : abssio <=s ? color.red :color.orange):na)

Return to “Pine Script Q&A”