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)
|
Try this combined Long (+/-1) and Short (+/-0.5) signals latch code:
[code:1:4865ecdc98]
===========================
System Long & Short signals
===========================
---8<---------------------------
{ Combined Long & Short System trade signals }
{ ©Copyright 2005 Jose Silva
For personal use only.
http://www.metastocktools.com }
{ Note: preference given to new entry or exit
signal if simultaneous entry & exit signals
on the same bar }
{ Reference Long signals }
LE:=C>Mov(C,3,E);
LX:=C<Mov(C,3,E);
{ Reference Short signals }
SE:=C<SAR(0.02,0.2);
SX:=C>SAR(0.02,0.2);
{ User inputs }
plot:=Input("Signals: [1]Clean, [2]All, [3]Trade binary",1,3,1);
delay:=Input("Entry and Exit delay",-1,5,0);
{ Long signals }
Init:=Cum(IsDefined(LE+LX+SE))=1;
entry:=LE AND (Alert(LE=0,2) OR Init);
exit:=(LX OR SE) AND (Alert((LX OR SE)=0,2)
OR Init);
binLong:=ValueWhen(1,entry-exit<>0,entry-exit);
{ Short signals }
Init:=Cum(IsDefined(SE+SX+LE))=1;
entry:=SE AND (Alert(SE=0,2) OR Init);
exit:=(SX OR LE) AND (Alert((SX OR LE)=0,2)
OR Init);
binShort:=ValueWhen(1,entry-exit<>0,entry-exit);
{ Combined Long & Short Signals }
binary:=(binLong-binShort)/2;
longEn:=binary>0 AND Alert(binary<1,2)
OR Cum(binary>0)=1;
longEx:=binary<1 AND Alert(binary>0,2);
long:=longEn-longEx;
shortEn:=binary<0 AND Alert(binary>-1,2)
OR Cum(binary<0)=1;
shortEx:=binary>-1 AND Alert(binary<0,2);
short:=shortEx-shortEn;
{ Plot signals in own window }
Ref(If(plot=1,short*.5,
If(plot=2,(SX-SE)*.5,binary)),-delay);
Ref(If(plot=1,long,
If(plot=2,LE-LX,binary)),-delay)
---8<---------------------------
[/code:1:4865ecdc98]
jose '-)
|