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
|