PureBytes Links
Trading Reference Links
|
A few days ago I posted a question on a formula. The answer was I couldn't
do it easily because it required a loop which Metastock does not support. A
good example of hard coding was presented. However, I took up the challenge
to perform a loop in Metastock. What I came up functions like a loop. The
disadvantage is that there are limits to how many iterations can be done in
the loop, basically you run out of room.
The formula below is for Rafter's Moving Trend, which is the same as the
Linear Regression Indicator in Metastock.
the loop implements the below
n=20;
for(i = n; i > 0; i--)
sum += (i - (n + 1) / 3) * close(i - n);
I used the ability to do x=x+y and the ability to reuse a variable, then
put in an if statement to see if the loop was finished.
Hope this can help in the future
Tom
--- Rafter Moving Trend, or the Metastock Linear Regression Indicator ---
pds:=20; {must be between 1 and 30}
k1:=(pds+1)/3;
k2:=6/(pds*(pds+1));
n:=pds;
{start pseudo loop}
x:=(n-k1)*CLOSE; {"0" bar}
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds))); {-1 bar}
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds)));
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds))); {-3}
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds)));
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds)));
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds))); {-6}
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds)));
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds)));
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds))); {-9}
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds)));
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds)));
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds))); {-12}
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds)));
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds)));
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds))); {-15}
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds)));
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds)));
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds))); {-18}
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds)));
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds)));
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds))); {-21}
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds)));
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds)));
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds))); {-24}
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds)));
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds)));
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds))); {-27}
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds)));
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds)));
n:=n-1;
x:=If(n<=0,x,x+(n-k1)*Ref(C,(n-pds))); {-30}
{end pseudo loop}
wt:=x*k2;
wt
------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/zMEolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/Metastockusers/
<*> To unsubscribe from this group, send an email to:
Metastockusers-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|