Hello everyone,
Could anyone please convert the trading view code of "cyclic Smoothed RSI_cRSI" below to amibroker code afl
===========================================
study(title="RSI cyclic smoothed", shorttitle="cRSI")
src = close
domcycle = input(20, minval=10, title="Dominant Cycle Length")
crsi = 0.0
cyclelen = domcycle / 2
vibration = 10
leveling = 10.0
cyclicmemory = domcycle * 2
//set min/max ranges?
h1 = hline(30, color=color.silver, linestyle=hline.style_dashed)
h2 = hline(70, color=color.silver, linestyle=hline.style_dashed)
torque = 2.0 / (vibration + 1)
phasingLag = (vibration - 1) / 2.0
up = rma(max(change(src), 0), cyclelen)
down = rma(-min(change(src), 0), cyclelen)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)
crsi := torque * (2 * rsi - rsi[phasingLag]) + (1 - torque) * nz(crsi[1])
lmax = -999999.0
lmin = 999999.0
for i = 0 to cyclicmemory - 1 by 1
if nz(crsi, -999999.0) > lmax
lmax := nz(crsi)
lmax
else
if nz(crsi, 999999.0) < lmin
lmin := nz(crsi)
lmin
mstep = (lmax - lmin) / 100
aperc = leveling / 100
db = 0.0
for steps = 0 to 100 by 1
testvalue = lmin + mstep * steps
above = 0
below = 0
for m = 0 to cyclicmemory - 1 by 1
below := below + iff(crsi[m] < testvalue, 1, 0)
below
ratio = below / cyclicmemory
if ratio >= aperc
db := testvalue
break
else
continue
ub = 0.0
for steps = 0 to 100 by 1
testvalue = lmax - mstep * steps
above = 0
for m = 0 to cyclicmemory - 1 by 1
above := above + iff(crsi[m] >= testvalue, 1, 0)
above
ratio = above / cyclicmemory
if ratio >= aperc
ub := testvalue
break
else
continue
lowband = plot(db, "LowBand", color.aqua)
highband = plot(ub, "HighBand", color.aqua)
fill(h1, h2, color=color.silver, transp=90)
fill(lowband, highband, color=color.gray, transp=90)
plot(crsi, "CRSI", color.fuchsia)
=================================
thanks in advance
Could anyone please convert the trading view code of "cyclic Smoothed RSI_cRSI" below to amibroker code afl
===========================================
study(title="RSI cyclic smoothed", shorttitle="cRSI")
src = close
domcycle = input(20, minval=10, title="Dominant Cycle Length")
crsi = 0.0
cyclelen = domcycle / 2
vibration = 10
leveling = 10.0
cyclicmemory = domcycle * 2
//set min/max ranges?
h1 = hline(30, color=color.silver, linestyle=hline.style_dashed)
h2 = hline(70, color=color.silver, linestyle=hline.style_dashed)
torque = 2.0 / (vibration + 1)
phasingLag = (vibration - 1) / 2.0
up = rma(max(change(src), 0), cyclelen)
down = rma(-min(change(src), 0), cyclelen)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)
crsi := torque * (2 * rsi - rsi[phasingLag]) + (1 - torque) * nz(crsi[1])
lmax = -999999.0
lmin = 999999.0
for i = 0 to cyclicmemory - 1 by 1
if nz(crsi, -999999.0) > lmax
lmax := nz(crsi)
lmax
else
if nz(crsi, 999999.0) < lmin
lmin := nz(crsi)
lmin
mstep = (lmax - lmin) / 100
aperc = leveling / 100
db = 0.0
for steps = 0 to 100 by 1
testvalue = lmin + mstep * steps
above = 0
below = 0
for m = 0 to cyclicmemory - 1 by 1
below := below + iff(crsi[m] < testvalue, 1, 0)
below
ratio = below / cyclicmemory
if ratio >= aperc
db := testvalue
break
else
continue
ub = 0.0
for steps = 0 to 100 by 1
testvalue = lmax - mstep * steps
above = 0
for m = 0 to cyclicmemory - 1 by 1
above := above + iff(crsi[m] >= testvalue, 1, 0)
above
ratio = above / cyclicmemory
if ratio >= aperc
ub := testvalue
break
else
continue
lowband = plot(db, "LowBand", color.aqua)
highband = plot(ub, "HighBand", color.aqua)
fill(h1, h2, color=color.silver, transp=90)
fill(lowband, highband, color=color.gray, transp=90)
plot(crsi, "CRSI", color.fuchsia)
=================================
thanks in advance