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

Notification

Icon
Error

Options
Go to last post Go to first unread
tinalee  
#1 Posted : Friday, June 17, 2011 5:37:27 AM(UTC)
tinalee

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 6/17/2011(UTC)
Posts: 4

I am a newbie Metastock user, Can someone help to code the following conditions.

1.close price be above its 100MA for at least 50 days AND

2. the slope of 50MA calculated over 100 days must be positive for at least 30 days.

Many thanks for your guidance!

jjstein  
#2 Posted : Friday, June 17, 2011 11:15:08 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Well, we're all newbies sometime -- it helps to fiddle with existing code...

Here's what you described:
---------------------------
MAshort:=Mov(C,50,S);
MAlong:=Mov(C,100,S);
Slope:=MAshort>Ref(MAshort,-1);

Sum(C>MAlong,50)>=50
AND Sum(Slope,100)>=30;


Not sure why you wanted a postive slope of 30 out of 100; you might experiment by changing that last line to "AND Sum(Slope,30)>=30;"

Also, you can use INPUT variables to change the parameters, without modifying the code. The above would look like this:

MA1:=Input("Short MA",1,500,50);
MA2:=Input("Long MA",1,500,100);
Length1:=Input("Close over MA",1,500,50);
SlopePositive:=Input("Slope Positive",1,500,30);
SlopePeriod:=Input("Slope Period",1,500,100);

MAshort:=Mov(C,MA1,S);
MAlong:=Mov(C,MA2,S);
Slope:=MAshort>Ref(MAshort,-1);

Sum(C>MAlong,Length1)>=Length1
AND Sum(Slope,SlopePeriod)>=SlopePositive;


Note that there is a limit of six (6) INPUT variables and a limit of 20 variables total in an indicator.

If you are going to "scan" in an Exploration, INPUT cannot be used, BUT you can "call" the indicator using FML and/or FMLVAR -- just set the "default" parameter to what you want to use in the Exploration.

Put the FML code in the FILTER tab; if you want to see the indicator value, put the exact same code in one of the Exploration COLUMNS.

Have fun.

tinalee  
#3 Posted : Friday, June 17, 2011 6:54:41 PM(UTC)
tinalee

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 6/17/2011(UTC)
Posts: 4

Thank you very much Johnathan, your comment is very helpful.

But from my understanding of condition 2, it is not a positive slope of 30 out of 100,

instead my version is like this:

sum(linregslope(MAshort,100)>0,30)>=30

that is: all of the last 30 slope is >0, and each slope is calculated over 100 period on 50MA.

Is my coding correct?

jjstein  
#4 Posted : Friday, June 17, 2011 7:53:48 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Well, it wasn't quite clear to me from your description what the "30" & "100" meant -- in plain language, if it means the slope of a 100-period regression line of the 50 SMA staying positive for 30 periods, then your code looks right.

Although, since a regression line is used, I'd skip the 50 SMA and use regression on the close. Gets you closer to the data...

If it means something else, you'll have to clarify. It might help to quote the source.

tinalee  
#5 Posted : Saturday, June 18, 2011 1:36:48 AM(UTC)
tinalee

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 6/17/2011(UTC)
Posts: 4

Got it. Thanks, Johnathan.
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.