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

Notification

Icon
Error

Options
Go to last post Go to first unread
catchai  
#1 Posted : Monday, August 1, 2011 3:12:58 AM(UTC)
catchai

Rank: Newbie

Groups: Registered, Registered Users
Joined: 8/1/2011(UTC)
Posts: 2

Hi everybody,

I am very new to metastock and I am trying to key in a formula for the following setup, would greatly appreciate if somebody can help me.

Buy setup
Signal 1 - If 8 EMA has crossed, or is already above 21 EMA
Filter 1 - Price is trading above 125 EMA
Filter 2 - 125 EMA is rising

Sell setup
Signal 1 - If 8 EMA crossed, or is already below 21 EMA
Filter 1 - Price is trading below 125 EMA
Filter 2 - 125 EMA is falling

Thanks so much
mstt  
#2 Posted : Monday, August 1, 2011 4:22:08 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Hi Catchai Your Filter 2 conditions are unnecessary because they are already covered by the Filter 1 conditions - the price ALWAYS moves towards an EMA or Wilders Smoothing. Therefore if the price is trading above an EMA then the EMA must be moving up towards the price, and if the price is below an EMA then the EMA must be moving down towards an EMA. This situation occurs because of the construction of an EMA and does not apply to other types of moving averages (Wilders Smoothing is just a slower form of EMA). As for each Signal 1, there is little point in including a Cross() function if you're going to AND it with a > or < operator. Since the price is virtually never going to be the same as an EMA (another feature of the way an EMA is calculated) it can be assumed that a Cross will add no new information to each series of > or < conditions. So to the code. {Buy setup} Signal1:=Mov(C,8,E)>Mov(C,21,E); Filter1:=C>Mov(C,125,E); Signal1 AND Filter1; {Sell setup} Signal1:=Mov(C,21,E)>Mov(C,8,E); Filter1:=Mov(C,125,E)>C; Signal1 AND Filter1; If these setups are used without any additional code you will get a whole series of contiguous TRUE signals. Using a Cross() function as below in place of the ">" expressions would give a TRUE only on the first bar of a series rather than on every bar. Assuming that you will apply a third event as the actual Buy or Sell signal there seems to be no value in using the Cross() function. {Buy setup} Signal1:=Cross(Mov(C,8,E),Mov(C,21,E)); Filter1:=C>Mov(C,125,E); Signal1 AND Filter1; {Sell setup} Signal1:=Cross(Mov(C,21,E),Mov(C,8,E)); Filter1:=Mov(C,125,E)>C; Signal1 AND Filter1; If all of your stated conditions were included then the code would look something like this. {Buy setup} Signal1:=Cross(Mov(C,8,E),Mov(C,21,E)) OR Mov(C,8,E)>Mov(C,21,E); Filter1:=C>Mov(C,125,E); Filter2:=Mov(C,125,E)>Ref(Mov(C,125,E),-1); Signal1 AND Filter1 AND Filter2; {Sell setup} Signal1:=Cross(Mov(C,21,E),Mov(C,8,E)) OR Mov(C,21,E)>Mov(C,8,E); Filter1:=Mov(C,125,E)>C; Filter2:=Ref(Mov(C,125,E),-1)>Mov(C,125,E); Signal1 AND Filter1 AND Filter2; You asked for help to write this code. Now you really need to study the examples I've given and figure out for yourself what works, what doesn't work, and why. By researching the answers to your own questions you'll learn the MetaStock Formula Language much more quickly than if you look to others for help with each little blip along the way. By all means ask for help if you can't figure something out, but do make yourself familiar with the MetaStock Formula Language section of the User Manual. Roy
catchai  
#3 Posted : Monday, August 1, 2011 8:28:41 PM(UTC)
catchai

Rank: Newbie

Groups: Registered, Registered Users
Joined: 8/1/2011(UTC)
Posts: 2

Hi Roy,

Thanks for your guidance, I will test it and learn it and try to figure out what works and what doesn't.

Again, my sincere thanks.

Cheers
Catherine
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.