Hello,
this is my first sharing in ProRealCode.
I’ve converted the Adaptive Cycle Indicator from TradingView, that was coded by LazyBear: https://it.tradingview.com/script/3lV1e3ci-Ehlers-Adaptive-Cyber-Cycle-Indicator-LazyBear/
Feel free to contact me if you find bug or share the corrections.
Happy Trading.
This is the code for the indicator Adaptive Cyber Cycle:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
src=(high+low)/2 a=.07 s = (src + 2*src[1] + 2*src[2] + src[3])/6.0 if barindex < 7 then c = (src - 2*src[1] + src[2])/4 ac = (src-2*src[1]+src[2])/4 endif if barindex > 7 then c = ((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*ip[1]) I1 = c[3] if q1 <> 0 and q1[1] <> 0 then dp1 = (I1/q1 - I1[1]/q1[1]) / (1 + I1*I1[1]/(q1*q1[1])) else dp1 = 0 endif if dp1 < 0.1 then dp2 = 0.1 else if dp1 > 1.1 then dp2 = 1.1 else dp2 = dp1 endif endif myFNMED1 = CALL "[FN] MED"[dp2[2], dp2[3], dp2[4]] md = CALL "[FN] MED"[dp2, dp2[1], myFNMED1] if md = 0 then dc = 15 else dc = 6.28318 / md + 0.5 endif ip = .33*dc + .67*ip[1] p = .15*ip + .85*p[1] a1 = 2/(p+1) ac = ((1-0.5*a1)*(1-0.5*a)*(s-2*s[1]+s[2])+2*(1-a1)*ac[1]-(1-a1)*(1-a1)*ac[2]) t = ac[1] endif return ac as "Adaptive Cyber Cycle", t as "ACC[1]", 0 as "0" |
You need also to code the function “[FN] MED” called in the script.
1 |
MED"]return (x+y+z) - min(x,min(y,z)) - max(x,max(y,z)) |
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Hello Pietro
thanks for your code, could you suggest to use it?
Hi Ale,
the use is similar to other oscillator, mainly divergence.
In this link you will find some graphical example from lazybear that explain pretty well the use: https://it.tradingview.com/script/3lV1e3ci-Ehlers-Adaptive-Cyber-Cycle-Indicator-LazyBear/
Regards.
Hello people,
i’ve made a little modification in the code for eliminate the function call. Now the indicator should work much faster.
Enjoy.
// @author Pietro Fontana
// Kudos to LazyBear to made it in TradingView
src=typicalprice
a=.07
s = (src + 2*src[1] + 2*src[2] + src[3])/6.0
if barindex < 7 then
c = (src - 2*src[1] + src[2])/4
ac = (src-2*src[1]+src[2])/4
endif
if barindex > 7 then
c = ((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*ip[1])
I1 = c[3]
if q1 <> 0 and q1[1] <> 0 then
dp1 = (I1/q1 - I1[1]/q1[1]) / (1 + I1*I1[1]/(q1*q1[1]))
else
dp1 = 0
endif
if dp1 < 0.1 then
dp2 = 0.1
else
if dp1 > 1.1 then
dp2 = 1.1
else
dp2 = dp1
endif
endif
myFNMED1 = (dp2[2] + dp2[3] + dp2[4]) - min(dp2[2],min(dp2[3], dp2[4])) - max(dp2[2],min(dp2[3], dp2[4]))
md = (dp2 + dp2[1] + myFNMED1) - min(dp2,min(dp2[1], myFNMED1)) - max(dp2,min(dp2[1], myFNMED1))
if md = 0 then
dc = 15
else
dc = 6.28318 / md + 0.5
endif
ip = .33*dc + .67*ip[1]
p = .15*ip + .85*p[1]
a1 = 2/(p+1)
ac = ((1-0.5*a1)*(1-0.5*a)*(s-2*s[1]+s[2])+2*(1-a1)*ac[1]-(1-a1)*(1-a1)*ac[2])
t = ac[1]
endif
return ac as \"Adaptive Cyber Cycle\", t as \"ACC[1]\", 0 as \"0\"
Very cool! Thanks a lot for the update! much appreciated 🙂
Just a suggestion, not an expert, what happens if the barindex = 7
Hello … What does FN-MED mean exactly in the code complement? It is a mess to load the indicator!
Hi Alain,
in the comment there’s a version that does not require the call function, and is more fast, but don’t expect good performance, prorealcode was not built with performance in mind.
Ok thank you Pietro…
thank you for the code.
coded as per above, I encounter an error “unexpected character” (i.e. “ip” in line q1 = (.0962*c + 0.5769*c[2] – 0.5769*c[4] – .0962*c[6])*(0.5+.08*ip[1])
i suspect that may be because it ( ip) has not been previously defined. can you help please??
thank you
Hello there is a new version, is it possible to translate it?
https://www.tradingview.com/script/CPLfkmht-Ehlers-Stochastic-Cyber-Cycle/
bonjour,
PRT me demande de réduire la période d’adaptive cyber Cycle suite à de fort ralentissement de l’appli.
Lorsque je rajoute “defparam calculateonlastbars = 200”
Les 2 courbes disparaissent. Uniquement la ligne horizontale 0. Comment je peux faire ?
merci
christophe11560, i’ve coded this a long time ago for a different version of the PRT, i’m not using PRT anymore.
Have you tried with the code that i’ve posted in the comment, not the one that you can download? It’s faster.
@Gianluca, sorry but i don’t use PRT anymore, anyway what you linked is another indicator i think.
Best regards.