Rank: Newbie
Groups: Registered, Registered Users, Subscribers Joined: 1/28/2009(UTC) Posts: 2
|
Hello,
I am new to Metastock and I am trying to work out how to write a simple formula but I am unable to do it so I am hoping someone can help me here. It's should be very simple but still I cannot work out how to do it.
This is what I have so far -
EL:=H > Ref(HHV(H,20),-1); {Enter Long Position on a New 20 Period High}
CL:=L < Ref(LLV(L,10),-1); {Exit Long Position on a New 10 Period Low}
ES:=L < Ref(LLV(L,20),-1); {Enter Short Position on a New 20 Period Low}
CS:=H > Ref(HHV(H,10),-1); {Exit Short Position on a New 10 Period High}
EnterLongTrigger:= EL;
I want my "EnterLongTrigger" to only give me a signal to buy long if my previous trade WAS NOT Profitable.
In other words if my previous buy signal proved to be a profitable trade then disregard this buy signal.
How can I write this?
Thank You
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 11/7/2005(UTC) Posts: 602
|
Use the function ValueWhen(,,) to fetch the profit or loss. Give it a try, post back if you are still not able to do it and I will give it a try. You may also need the function BarsSince() to position the profit/loss calculation correctly.
|
|
|
|
Rank: Newbie
Groups: Registered, Registered Users, Subscribers Joined: 1/28/2009(UTC) Posts: 2
|
Thank you Johnl for setting me in the right direction. I have given it a go but I am unable to get it working. Any help much appreciated.
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 11/7/2005(UTC) Posts: 602
|
Hope this is close to what you were looking for?
p1:=Peak(2,H,10); p2:=Trough(2,L,5); {-----------------------------------} a1:=Cross(H,p1); a2:=Cross(p2,L); {-----------------------------------} b1:=ValueWhen(1,a1=1,C)-ValueWhen(1,a2=1,C); b2:=b1-Ref(b1,-1); b3:=If((b2>0),1,0); c1:=If((b3=1) AND (ValueWhen(2,b2<>0,b2)<0) ,2,0); b1;b3;c1
|
|
|
|
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.