Rank: Advanced Member
Groups: Registered, Registered Users Joined: 1/19/2005(UTC) Posts: 1,065 Location: Koh Pha-Ngan, Earth
Was thanked: 2 time(s) in 2 post(s)
|
Using Patrick' Latch, try something like this:
[code:1:e35e18baaf]
LastEntry:=entry and Cum(entry)=LastValue(Cum(entry));
LastExit:=exit and Cum(exit)=LastValue(Cum(exit));
LastEntry-LastExit
[/code:1:e35e18baaf]
Alternatively, use this MS indicator code:
[code:1:e35e18baaf]
====================
System trade signals
====================
---8<--------------------------
{ System trade signals v2.5 }
{ ©Copyright 2005 Jose Silva }
{ For personal use only }
{ http://www.metastocktools.com }
{ Note on simultaneous entry/exit on same bar:
#1 Ignore:
entry/exit signals cancel each other;
#2 Preference given to:
new entry if currently Short,
new exit if currently Long.}
{ Entry/Exit conditions - crossover example }
entry:=C>Mov(C,21,E);
exit:=C<Mov(C,10,E);
{ User inputs }
plot:=Input("Signals: [1]Clean, [2]All, [3]Trade binary",1,3,1);
choose:=Input("Simultaneous entry/exit: [1]Ignore, [2]Preference",1,2,2);
delay:=Input("Entry and Exit delay",-1,5,0);
{ Initialize }
Init:=Cum(IsDefined(entry+exit))=1;
{ #1 - Ignore entry/exit on same bar }
bin1:=ValueWhen(1,entry-exit<>0 OR Init,
entry-exit);
long:=bin1=1 AND (Alert(bin1<>1,2) OR Init);
short:=bin1=-1 AND (Alert(bin1<>-1,2) OR Init);
{ Remove all signals except last two }
long:=long and Cum(long)=LastValue(Cum(long));
short:=short and Cum(short)=LastValue(Cum(short));
signals1:=long-short;
{ #2 - Preference to first entry/exit }
long:=entry AND (Alert(entry=0,2) OR Init);
short:=exit AND (Alert(exit=0,2) OR Init);
bin2:=ValueWhen(1,long-short<>0 OR Init,
long-short);
long:=bin2=1 AND (Alert(bin2<1,2) OR Init);
short:=bin2=-1 AND (Alert(bin2>-1,2) OR Init);
{ Remove all signals except last two }
long:=long and Cum(long)=LastValue(Cum(long));
short:=short and Cum(short)=LastValue(Cum(short));
signals2:=long-short;
{ Select #1 or #2 }
binary:=If(choose=1,bin1,bin2);
signals:=If(choose=1,signals1,signals2);
{ Plot in own window }
Ref(If(plot=2,entry,0),-delay);
Ref(If(plot=1,signals,
If(plot=2,-exit,binary)),-delay)
---8<--------------------------
[/code:1:e35e18baaf]
jose '-)
http://www.metastocktools.com
.
|