Vanise
Pine Script Rookie
Pine Script Rookie
Posts: 2
Joined: September 28th, 2023

Converting v2 to v5

Hello guys.
I have old but very useful pinescript coded on v2. I've tried so many times to convert but no result and at the end I give up.
Can anyone help me to convert? This indicator does MA Auto adaptive following cycle lenght and volatility. A linear regression of the MA is adds and gives the signal when cross MA. Adjustable value.

Thanks in advance.


Code: Select all

//@version=2
study("MA ", shorttitle="MA", overlay=true, precision=3)
src=input(high, title="Source") 
a=input(.07,step=0.01, title="Alpha")
s = (src + 2*src[1] + 2*src[2] + src[3])/6.0
c = n<7?(src - 2*src[1] + src[2])/4.0:((1 - 0.5*a)*(1 - 0.5*a)*(s - 2*s[1] + s[2]) + 2*(1-a)*c[1] - (1 - a)*(1-a)*c[2])
q1 = (.0962*c + 0.5769*c[2] - 0.5769*c[4] - .0962*c[6])*(0.5+.08*nz(ip[1]))
I1 = c[3]
dp_ = iff(q1 != 0 and q1[1] != 0, (I1/q1 - I1[1]/q1[1]) / (1 + I1*I1[1]/(q1*q1[1])),0)
dp = iff(dp_ < 0.1, 0.1, iff(dp_ > 1.1, 1.1, dp_))
med(x,y,z) => (x+y+z) - min(x,min(y,z)) - max(x,max(y,z))
md = med(dp,dp[1], med(dp[2], dp[3], dp[4]))
dc = iff(md == 0, 15, 6.28318 / md + 0.5)
ip = .33*dc + .67*nz(ip[1])
p = .15*ip + .85*nz(p[1])

a1 = 2.0/(p/2 + 1)
a2=2.0/(p + 1)
mul=input(1.5,"mult",step=0.1)
amaLength=20
diff=abs(close[0]-close[1])
signal=abs(close-close[amaLength])
noise=sum(diff, amaLength)
efratio=noise!=0 ? signal/noise : 1
EF=efratio
len = 3

TrueRange = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1])))
DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0
DirectionalMovementMinus = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0
SmoothedTrueRange = nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/len) + TrueRange
SmoothedDirectionalMovementPlus = nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1])/len) + DirectionalMovementPlus
SmoothedDirectionalMovementMinus = nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1])/len) + DirectionalMovementMinus
DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
DX = 1-(abs(DIPlus-DIMinus) / (DIPlus+DIMinus))
ADX = sma(DX, len)

smo=input(20,"filter RMS")
ER=(1-efratio)*ADX
SC=(ER*(a1-a2)+a2)
RMSa= sum( SC*SC, smo)
RMS= sqrt(RMSa/smo)*mul
out=nz(out[1])+RMS*(src-nz(out[1]))

lel=input(14,"lin reg lenght")
olr=input(3,"offset lin reg")
lr=linreg(out,lel,olr)
col=out>lr?lime:red
l=plot(lr,color=silver,title="Reg Lin",linewidth=1)
o=plot(out,color=col,title="MA",linewidth=2)
fill(l,o,color=col,transp=70)

Steve Burman
Moderator
Moderator
Posts: 109
Joined: January 13th, 2023

Re: Converting v2 to v5

Hi Vanise,

Unfortunately this cannot be easily converted or in fact converted at all. There is a missing variable n which is not defined so it seems a line of code is missing. I even tried using ChatGPT to convert it but it also failed. I strongly suggest you try contacting the author of the script.

Vanise
Pine Script Rookie
Pine Script Rookie
Posts: 2
Joined: September 28th, 2023

Re: Converting v2 to v5

Steve Burman wrote:
Wed Oct 04, 2023 11:13 pm
Hi Vanise,

Unfortunately this cannot be easily converted or in fact converted at all. There is a missing variable n which is not defined so it seems a line of code is missing. I even tried using ChatGPT to convert it but it also failed. I strongly suggest you try contacting the author of the script.
Thanks alot for the reply. True, I've tried multiple ways but no result. Even hired a coder and no result.
Thanks alot again :up:

Return to “Pine Script Q&A”