Rank: Newbie
Groups ready for retrieval: Registered, Registered Users, Subscribers Joined: 9/29/2008(UTC) Posts: 4
|
Hi, As no one answered, I will post my code here:
First, I use the following formula to calculate the Cyber Cycle: Code: {Cyber Cycle} alpha := 0.07; pr := (H+L)/2; Smooth := (pr + 2*Ref(pr,-1) + 2*Ref(pr,-2) + Ref(pr,-3))/6; Cycle := (1-0.5*alpha)*(1-0.5*alpha)*(Smooth-2*Ref(Smooth,-1) + Ref(Smooth,-2)) + 2*(1-alpha) *PREV - (1-alpha)*(1-alpha)*Ref(PREV,-1); Cycle := If(Cum(1) < 7,(pr - 2*Ref(pr,-1) + Ref(pr,-2)) / 4,Cycle); Cycle;
The above formula is used to calculate the Instantaneious Period in the following formula: Code: {Instantaneous Cycle Period} Quadrature := (0.0962* Fml("Cyber Cycle") + 0.5769*Ref(Fml("Cyber Cycle"),-2) - 0.5769*Ref(Fml("Cyber Cycle"),-4) -0.0962*Ref(Fml("Cyber Cycle"),-6))*(0.5 + 0.08*PREV); InPhase := Ref(Fml("Cyber Cycle"),-3); DeltaPhase := (InPhase/Quadrature -Ref(InPhase,-1)/Ref(Quadrature,-1)) / (1 + InPhase*Ref(InPhase,-1)/(Quadrature*Ref(Quadrature,-1))); DeltaPhase := If(DeltaPhase < 0.1,0.1,DeltaPhase); DeltaPhase := If(DeltaPhase > 1.1,1.1,DeltaPhase); MedianDelta := Mid(DeltaPhase,5); DC := If(MedianDelta = 0,15,6.28318/MedianDelta +0.5); InstPeriod := 0.33*DC + 0.67*PREV; InstPeriod;
Finally, the above formula is then used to calculate the Dominat Cycle Period: Code: {Dominant Cycle Period} Period := 0.15*Fml("Instantaneous Cycle Period") + 0.85*PREV; Period;
For
testing, I created a data set with an exact 20 period cycle , but my
code give me results variyng from 19 to 25, aproximately (interestingly, the result is a sine line - should be a horizontal line).
The code is a direct translation of the Easy Language in Ehlers book "Cybernetic Analisys...".
I can´t figure out where is the flaw. I even guessed if there is some error in the original code. Ehlers told me MetaStock already ported his formulas to MSFL, but as MetaStock support is ignoring my emails about this subject, here I am reinventing the wheel.
Can someone help me?
|