logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Jniaj  
#1 Posted : Wednesday, October 1, 2008 10:58:10 AM(UTC)
Jniaj

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?
wabbit  
#2 Posted : Saturday, October 4, 2008 10:57:10 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Your "Quadrature" variable in the {Instantaneous Cycle Period} is incorrect; the variable is not self referencing, it refers to the previous value if "InstPeriod". There may be other errors too, but this is where I stopped reading.

You have made a great attempt to achieve this in MSFL, but unfortunately the true reflection of Ehlers' code is not possible in MSFL and requires to be written as an external function, or in another application like Excel and imported back into MS.


wabbit [:D]

Jniaj  
#3 Posted : Wednesday, October 8, 2008 12:16:32 PM(UTC)
Jniaj

Rank: Newbie

Groups ready for retrieval: Registered, Registered Users, Subscribers
Joined: 9/29/2008(UTC)
Posts: 4

Excuse me, but in the original code of the quadrature there is not self reference, but a reference to InstPeriod of the last bar, exactly as I did.
So, the error is not in the quadrature calculation.
Here is the original code:

Code:
Q1 = (.0962*Cycle + .5769*Cycle[2] - .5769*Cycle[4]
-.0962*Cycle[6])*(.5 + .08*InstPeriod[1]);

wabbit  
#4 Posted : Wednesday, October 8, 2008 10:03:54 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Code:

cyc:=Fml("Cyber Cycle");
Quadrature := (0.0962*cyc + 0.5769*Ref(cyc,-2) - 0.5769*Ref(cyc,-4) - 0.0962*Ref(cyc,-6))*(0.5 + 0.08*PREV);
In your line of code (modified slightly for speed and clarity), the PREV refers to the previous value of the Quadrature variable, not the containing function.

A simple demonstration of the PREV function:
Code:

x:= PREV +1;

{plot}
x;

This simply plots a line that increases by a value of 1 for each bar, starting at 1 on the first bar because PREV has a value of zero. It doesn't demonstrate whether the PREV is taking the previous value of the containing function or the variable so we add to the code:
Code:

x:= PREV +1;
y:=2;

{plot}
x;
y;

Here we notice the 'x' line is unchanged , showing PREV as using the previous value of the variable not the function, as the function now has a constant value of 2.

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;

Looking again at your code; if we accept the limitation that MS codes are fully evaluated, line by line there is no way to refer to the previous value of InstPeriod in the Quadrature variable because the InstPeriod variable is not calculated until the end of the function. (We do notice though, the InstPeriod is self-referenced.)


I hope this helps.

wabbit [:D]

P.S.

Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.