[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[EquisMetaStock Group] A better trade binary



PureBytes Links

Trading Reference Links


I recently stumbled on an improvement to the basic trade binary code, 
which allows the use of ValueWhen() instead of BarsSince() MetaStock 
functions.

Avoiding the BarsSince() function means that the indicator code now 
does not need to wait for the first entry signal before plotting an 
exit signal.  This is best illustrated by plotting and comparing the 
two trade signal indicators below.


MetaStock -> Tools -> Indicator Builder -> New ->
Copy and paste complete formulae between "---8<---" lines.


====================
System trade signals
====================
---8<--------------------------

{ System trade signals - note: simultaneous
  Long/Short signals cancel each other }
{ http://www.metastocktools.com }

{ Signals reference 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);
delay:=Input("Entry and Exit delay",-1,5,0);

{ Clean signals }
x:=ValueWhen(1,entry-exit<>0,entry-exit);
long:=x=1
 AND (Alert(x<>1,2) OR Cum(IsDefined(x))=1);
short:=x=-1
 AND (Alert(x<>-1,2) OR Cum(IsDefined(x))=1);
signals:=long-short;
binary:=ValueWhen(1,signals<>0,signals);

{ Plot in own window }
Ref(If(plot=1,signals,
 If(plot=2,entry-exit,binary)),-delay)

---8<--------------------------


===============================
System trade signals - original
===============================
---8<--------------------------

{ Original trade signals code }
{ BarsSince() function prevents first exit plot}
{ With thanks to Roy Larsen at
  http://www.metastocktips.co.nz }

{ Signals reference 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);
delay:=Input("Entry and Exit delay",-1,5,0);

{ Clean signals }
Init:=Cum(entry+exit>-1)=1;
entryInit:=Cum(entry)=1;
flag:=BarsSince(Init OR entry)
 <BarsSince(Init OR exit)+entryInit;
signals:=(entryInit AND Alert(entryInit=0,2)
  OR flag AND Alert(flag=0,2))
   -(flag=0 AND Alert(flag,2));
binary:=ValueWhen(1,signals<>0,signals);

{ Plot in own window }
Ref(If(plot=1,signals,
 If(plot=2,entry-exit,binary)),-delay)

---8<--------------------------


jose '-)
http://www.metastocktools.com









------------------------ Yahoo! Groups Sponsor --------------------~--> 
Has someone you know been affected by illness or disease?
Network for Good is THE place to support health awareness efforts!
http://us.click.yahoo.com/Rcy2bD/UOnJAA/cosFAA/BefplB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/equismetastock/

<*> To unsubscribe from this group, send an email to:
    equismetastock-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/