I am trying to convert the the following Pine Script V2 Code to V4 or V5. I have tried updating the code automatically using the the 3 dots on upper right side and manually but have no luck. Mostly having issues on converting line 13, 14, 16, 17, 20, 21, 24, 25, 26, 30, 36, 37.
1) strategy("Ehlers MESA Adaptive Moving Average", shorttitle="EMAMA2", overlay=true, precision=3)
2) //Heikin Ashi
3) res = input(title="Resolution", type=resolution, defval="60")
4) haTicker = heikinashi(tickerid)
5) haClose = security(haTicker, res, close)
6) src = input(hlc3, title="Source")
7) fl = input(.8, title="Fast Limit")
8) sl = input(.035, title="Slow Limit")
9) fl2 = input(0.0, title="Fast Limit 2")
10) sl2 = input(.02, title="Slow Limit 2")
11) pi = 3.1415926
12) sp = (4*src + 3*src[1] + 2*src[2] + src[3]) / 10.0
13) dt = (.0962*sp + .5769*nz(sp[2]) - .5769*nz(sp[4]) - .0962*nz(sp[6])) * (.075*nz(p[1]) + .54)
14) q1 = (.0962*dt + .5769*nz(dt[2]) - .5769*nz(dt[4]) - .0962*nz(dt[6])) * (.075*nz(p[1]) + .54)
15) i1 = nz(dt[3])
16) jI = (.0962*i1 + .5769*nz(i1[2]) - .5769*nz(i1[4]) - .0962*nz(i1[6])) * (.075*nz(p[1]) + .54)
17) jq = (.0962*q1 + .5769*nz(q1[2]) - .5769*nz(q1[4]) - .0962*nz(q1[6])) * (.075*nz(p[1]) + .54)
18) i2_ = i1 - jq
19) q2_ = q1 + jI
20) i2 = .2*i2_ + .8*nz(i2[1])
21) q2 = .2*q2_ + .8*nz(q2[1])
22) re_ = i2*nz(i2[1]) + q2*nz(q2[1])
23) im_ = i2*nz(q2[1]) - q2*nz(i2[1])
24) re = .2*re_ + .8*nz(re[1])
25) im = .2*im_ + .8*nz(im[1])
26) p1 = iff(im!=0 and re!=0, 2*pi/atan(im/re), nz(p[1]))
27) p2 = iff(p1 > 1.5*nz(p1[1]), 1.5*nz(p1[1]), iff(p1 < 0.67*nz(p1[1]), 0.67*nz(p1[1]), p1))
28) p3 = iff(p2<6, 6, iff (p2 > 50, 50, p2))
29) p = .2*p3 + .8*nz(p3[1])
30) spp = .33*p + .67*nz(spp[1])
31) phase = 180/pi * atan(q1 / i1)
32) dphase_ = nz(phase[1]) - phase
33) dphase = iff(dphase_< 1, 1, dphase_)
34) alpha_ = fl / dphase
35) alpha = iff(alpha_ < sl, sl, iff(alpha_ > fl, fl, alpha_))
36) mama = alpha * src + (1 - alpha) * nz(mama[1])
37) fama = .5 * alpha * mama + (1 - .5 * alpha) * nz(fama[1])
38) famal = plot(fama, title="FAMA", color=white, transp=0, linewidth=3)
39) alpha_2 = fl2 / dphase
40) alpha2 = iff(alpha_2 < sl2, sl2, iff(alpha_2 > fl2, fl2, alpha_2))
41) mama2 = alpha2 * src + (1 - alpha2) * nz(mama2[1])
42) fama2 = .5 * alpha2 * mama2 + (1 - .5 * alpha2) * nz(fama2[1])
43) famal2 = plot(fama2, title="FAMA2", color=white, transp=0, linewidth=3)
44) longCondition = crossover(haClose, fama) and (haClose >= fama2)
45) if (longCondition)
46) strategy.entry("Long Entry Id", strategy.long)
47) alertcondition(longCondition, title='Buy Long', message='Buy Long')
48) closeLong = strategy.close_all(crossunder(haClose, fama))
49) alertcondition(longCondition == false, title='Close Long', message='Close Long')
50) shortCondition = crossunder(haClose, fama) and (haClose <= fama2)
51) if (shortCondition)
52) strategy.entry("Short Entry Id", strategy.short)
53) alertcondition(shortCondition, title='Buy Short', message='Buy Short')
54) closeShort = strategy.close_all(crossover(haClose, fama))
55) alertcondition(shortCondition == false, title='Close Short', message='Close Short')
I have tried to used VAR = 0 for the lines listed since the code is calling undeclared identifer.
strategy('Ehlers MESA Adaptive Moving Average', shorttitle='EMAMA2', overlay=true, precision=3)
//Heikin Ashi
res = input('180', 'Resolution')
haTicker = ticker.heikinashi(syminfo.tickerid)
haClose = request.security(haTicker, res, close)
//haClose = request.security(ticker.heikinashi(syminfo.tickerid), res, close)
src = input(hlc3, title='Source')
fl = input(.8, title='Fast Limit')
sl = input(.035, title='Slow Limit')
fl2 = input(0.0, title='Fast Limit 2')
sl2 = input(.02, title='Slow Limit 2')
pi = 3.1415926
var p = 0.
sp = (4 * src + 3 * src[1] + 2 * src[2] + src[3]) / 10.0
dt = (.0962 * sp + .5769 * nz(sp[2]) - .5769 * nz(sp[4]) - .0962 * nz(sp[6])) * (.075 * nz(p[1]) + .54)
q1 = (.0962 * dt + .5769 * nz(dt[2]) - .5769 * nz(dt[4]) - .0962 * nz(dt[6])) * (.075 * nz(p[1]) + .54)
i1 = nz(dt[3])
jI = (.0962 * i1 + .5769 * nz(i1[2]) - .5769 * nz(i1[4]) - .0962 * nz(i1[6])) * (.075 * nz(p[1]) + .54)
jq = (.0962 * q1 + .5769 * nz(q1[2]) - .5769 * nz(q1[4]) - .0962 * nz(q1[6])) * (.075 * nz(p[1]) + .54)
i2_ = i1 - jq
q2_ = q1 + jI
var i2 = 0.
var q2 = 0.
var re = 0.
var im = 0.
var spp = 0.
var mama = 0.
var fama = 0.
var fama2 = 0.
var mama2 = 0.
i2 := .2 * i2_ + .8 * i2
q2 := .2 * q2_ + .8 * q2
re_ = i2 * nz(i2[1]) + q2 * nz(q2[1])
im_ = i2 * nz(q2[1]) - q2 * nz(i2[1])
re := .2 * re_ + .8 * re
im := .2 * im_ + .8 * im
p1 = im != 0 and re != 0 ? 2 * pi / math.atan(im / re) : nz(p[1])
iff_1 = p1 < 0.67 * nz(p1[1]) ? 0.67 * nz(p1[1]) : p1
p2 = p1 > 1.5 * nz(p1[1]) ? 1.5 * nz(p1[1]) : iff_1
iff_2 = p2 > 50 ? 50 : p2
p3 = p2 < 6 ? 6 : iff_2
p := .2 * p3 + .8 * nz(p3[1])
spp := .33 * p + .67 * spp
phase = 180 / pi * math.atan(q1 / i1)
dphase_ = nz(phase[1]) - phase
dphase = dphase_ < 1 ? 1 : dphase_
alpha_ = fl / dphase
iff_3 = alpha_ > fl ? fl : alpha_
alpha = alpha_ < sl ? sl : iff_3
mama := alpha * src + (1 - alpha) * mama
fama := .5 * alpha * mama + (1 - .5 * alpha) * fama
famal = plot(fama, 'FAMA', color.new(color.white, 1), linewidth=3)
alpha_2 = fl2 / dphase
iff_4 = alpha_2 > fl2 ? fl2 : alpha_2
alpha2 = alpha_2 < sl2 ? sl2 : iff_4
mama2 := alpha2 * src + (1 - alpha2) * mama2
fama2 := .5 * alpha2 * mama2 + (1 - .5 * alpha2) * fama2
famal2 = plot(fama2, 'FAMA2', color.new(color.white, 1), linewidth=3)
longCondition = ta.crossover(haClose, fama) and haClose >= fama2
if longCondition
strategy.entry('Long Entry Id', strategy.long)
//alertcondition(longCondition, title='Buy Long', message='Buy Long')
//closeLong = strategy.close_all(crossunder(haClose, fama))
//alertcondition(longCondition == false, title='Close Long', message='Close Long')
shortCondition = ta.crossunder(haClose, fama) and haClose <= fama2
if shortCondition
strategy.entry('Short Entry Id', strategy.short)
//alertcondition(shortCondition, title='Buy Short', message='Buy Short')