Hello,
I’m trying to convert this Ehlers Deycler indicator from TradingView but I can’t seem to get it work.
Here is my code:
// Input parameters
length = 60
src = close
// Constants
once PI = 3.141592653589793
// Variables
PIx2Length = 2 * PI / length
cosValue = cos(PIx2Length)
alpha = 0
If (cosValue <> 0) then
alpha = (cosValue + sin(PIx2Length) - 1) / cosValue
else
If (barindex > 1) then
alpha = alpha[1]
endif
endif
decycler = alpha / 2 * (src + src[1]) + (1 - alpha) * decycler[1]
// Plotting the Decycler
return decycler AS "Decycler"
I would appreciate if someone could point me to my mistake(s).
Thanks JS!
Although the indicators share the same name, the calculation is not the exactly the same.
JSParticipant
Senior
True, but all the Decyclers I’ve seen have a different calculation… 🙂
It’s such a difficult subject that I can’t judge which calculation is the right one…
You only have to convert radians to degrees.
PIx2Length=2*PI/length
transf = PIx2Length*360/(2*PI)
cosine=COS(transf)
PRT works with degrees and TV works with radians. Here you have the code:
//-----Inputs------------------------------------//
length=60
src=close
colorMA=1
//-----------------------------------------------//
//-----Moving average calculation----------------//
once PI = 3.14159265359
if barindex > length then
PIx2Length=2*PI/length
transf = PIx2Length*360/(2*PI)
cosine=COS(transf)
alpha=0
if cosine<>0 then
alpha=(cosine+sin(transf)-1)/cosine
else
alpha=alpha[1]
endif
MA=0
MA=alpha/2*(src+src[1])+(1-alpha)*MA[1]
//-----------------------------------------------//
//-----Color MA configuration--------------------//
if colorMA then
if MA>MA[1] then
r=0
g=255
elsif MA<MA[1] then
r=255
g=0
endif
endif
endif
return MA as "Decycler" coloured(r,g,0)style(line,2)