To create the
2/20-Day EMA Breakout
System by David Landry
in MetaStock for
Windows, choose System
Tester from the Tools
menu. Now choose new and
enter the following
system test rules and
options:
Signal
Formulas |
Enter
Long
Alert(Cross(Sum(L
>
Mov(C,20,E),2)
=
2,.5),10)
AND
HIGH
>=
Peak(1,Cross(Sum(L
>
Mov(C,20,E),2)
=
2,.5)
*
HHV(H,2),1)
+
.001{10
ticks}
AND
BarsSince(Cross(Sum(L
>
Mov(C,20,E),2)
=
2,.5))
<
BarsSince(LOW
<=
Mov(C,20,E)) |
Close
Long
LOW
<=
Mov(C,20,E) |
Enter
Short
Alert(Cross(Sum(H
<
Mov(C,20,E),2)
=
2,.5),10)
AND
LOW
<=
Peak(1,Cross(Sum(H
<
Mov(C,20,E),2)
=
2,.5)
*
LLV(L,2),1)
-
.001{10
ticks}
AND
BarsSince(Cross(Sum(H
<
Mov(C,20,E),2)
=
2,.5))
<
BarsSince(HIGH
>=
Mov(C,20,E)) |
Close
Short
HIGH
>=
Mov(C,20,E) |
|
- Initial equity
Points Only
- Positions Long
and short
- Trade price
Close
- Trade delay 0
Please note the {10
ticks} comment in the
system rules. The value
used in these rules is
for most currencies. You
should change this value
based upon the commodity
your testing.
(Go
Top...) |
MetaStock -> Tools ->
Indicator Builder -> New
Copy and paste all
formulae below. Plot
only last formula.
RorPlot1
If(Round(
(6.854*LinearReg(C,13)
+4.236*LinearReg(LinearReg(C,13),11)
+2.618*LinearReg(LinearReg(LinearReg(C,13),11),7)
+1.618*LinearReg(LinearReg(LinearReg(LinearReg(C,13),11),7),5)
+LinearReg(LinearReg(LinearReg(LinearReg(LinearReg(C,13),11),7),5),3))
/16.326*100)/100 > PREV
,If(Round(
(6.854*LinearReg(C,13)
+4.236*LinearReg(LinearReg(C,13),11)
+2.618*LinearReg(LinearReg(LinearReg(C,13),11),7)
+1.618*LinearReg(LinearReg(LinearReg(LinearReg(C,13),11),7),5)
+LinearReg(LinearReg(LinearReg(LinearReg(LinearReg(C,13),11),7),5),3))
/16.326*100)/100 -
(2.5*ATR(13)) > PREV
,Round(
(6.854*LinearReg(C,13)
+4.236*LinearReg(LinearReg(C,13),11)
+2.618*LinearReg(LinearReg(LinearReg(C,13),11),7)
+1.618*LinearReg(LinearReg(LinearReg(LinearReg(C,13),11),7),5)
+LinearReg(LinearReg(LinearReg(LinearReg(LinearReg(C,13),11),7),5),3))
/16.326*100)/100 -
(2.5*ATR(13))
,PREV)
,LinearReg(C,13))
RorPlot2
Tperiod:=13;
CFlow:=100000;
If(
Sum(WC()*V,13) > CFlow
AND (LinearReg(WC(),13)
+LinearReg(LinearReg(WC(),8),13)
+LinearReg(LinearReg(LinearReg(WC(),5),8),13)
+LinearReg(LinearReg(LinearReg(LinearReg(WC(),3),5),8),13)
+LinearReg(LinearReg(LinearReg(LinearReg(LinearReg(WC(),2),3),5),8),13))/5
> (LinearReg(Ref(WC(),-1),13)
+LinearReg(LinearReg(Ref(WC(),-1),8),13)
+LinearReg(LinearReg(LinearReg(Ref(WC(),-1),5),8),13)
+LinearReg(LinearReg(LinearReg(LinearReg(Ref(WC(),-1),3),5),8),13)
+LinearReg(LinearReg(LinearReg(LinearReg(LinearReg(Ref(WC(),-1),2),3),5),8),13))/5
AND LLVBars(WC(),Tperiod)
= Tperiod-1
AND PREV = 0
AND Mov(WC(),13,S) >
Mov(WC(),21,S)
,Tperiod-1
,If(PREV > Tperiod-2
AND Mov(WC(),13,S) >
Mov(WC(),21,S)
{AND Ref(Fml("RorPlot3"),-1)
> 24} {Invalid circular
reference!}
AND Fml("RorPlot1") >=
Ref(Fml("RorPlot1"),-1)
,PREV+1
,If(Mov(WC(),21,S) >=
Mov(WC(),13,S)
OR Sum(WC()*V,13) >
CFlow
OR Ref(Fml("RorPlot1"),-1)
> Fml("RorPlot1")
{OR Ref(Fml("RorPlot3"),-1)
< 25} {Invalid circular
reference!}
,0,PREV)))
RorPlot3
Round(
If(Fml("RorPlot2")>0,
If(Fml("RorPlot2")<52,
(5200/(Fml("RorPlot2")+1))*((LinearReg(WC(),13)
{-Ref(WC(),-Fml("RorPlot2"))
<--MS cannot handle
variables in Ref
function!}
-Ref(WC(),-20)) {<--
replaced with 20 period
Ref function!}
/LinearReg(WC(),13)),
100*((LinearReg(WC(),13)-LinearReg(Ref(WC(),-51),13))/LinearReg(WC(),13))),0))
(Go
Top...) |
{ True, Reverse &
MetaStock ATR v3.0 }{
©Copyright 2004 Jose
Silva }{ josesilva22@yahoo.com
}
{ Reverse True Range is
the the *smallest* of
the following for each
period:
* The distance from
today's High to today's
Low;
* The distance from
yesterday's Close to
today's High;
* The distance from
yesterday's Close to
today's Low.}
{ user input }
plot:=Input("[1]True ATR,
[2]Reverse ATR,
[3]Both,
[4]MS-ATR",1,4,1);
pds:=Input("Average True
Range
periods",1,252,10);
pdsN:=Input("normalizing
periods
(1=none)",1,2520,1);
smooth:=Input("Sine-weighted
smoothing? [1]Yes,
[0]No",0,1,0);
{ define True Range }
x1:=ValueWhen(2,1,C);
TrueRange:=Max(H-L,Max(Abs(x1-H),Abs(x1-L)));
RevTrueRange:=Min(H-L,Min(Abs(x1-H),Abs(x1-L)));
{ average True Range }
ATRtrue:=Mov(TrueRange,pds,E);
ATRrev:=Mov(RevTrueRange,pds,E);
ATRmeta:=Mov(TrueRange,pds*2-1,E);
{ normalize ATR }
ATRraw:=If(plot=1,ATRtrue,If(plot=2,ATRrev,If(plot=4,ATRmeta,ATRtrue)));
ATRnorm:=100*(ATRraw-LLV(ATRraw,pdsN))/(HHV(ATRraw,pdsN)-LLV(ATRraw,pdsN)+.000001);
ATRplot:=If(pdsN<2,ATRraw,ATRnorm);
rATRnorm:=100*(ATRrev-LLV(ATRrev,pdsN))/(HHV(ATRrev,pdsN)-LLV(ATRrev,pdsN)+.000001);
rATRplot:=If(pdsN<2,RevTrueRange,rATRnorm);
{ optional sine-weighted
smoothing }
ATRplot:=If(smooth=1,(Sin(30)*ATRplot
+Sin(60)*Ref(ATRplot,-1)
+Sin(90)*Ref(ATRplot,-2)
+Sin(60)*Ref(ATRplot,-3)
+Sin(30)*Ref(ATRplot,-4))
/(Sin(30)*2+Sin(60)*2+Sin(90)),ATRplot);
rATRplot:=If(smooth=1,(Sin(30)*rATRplot
+Sin(60)*Ref(rATRplot,-1)
+Sin(90)*Ref(rATRplot,-2)
+Sin(60)*Ref(rATRplot,-3)
+Sin(30)*Ref(rATRplot,-4))
/(Sin(30)*2+Sin(60)*2+Sin(90)),rATRplot);
{ plot ATR }
If(plot=3,rATRplot,ATRplot);
ATRplot
(Go
Top...) |
{ 2-point plot,
coding example v2.5 }{
Trendline choice 1: last
High/Low in month }{
Trendline choice 2: lows
at Jan/June 2004 }{
©Copyright 2003-2004
Jose Silva }{
josesilva22@yahoo.com }
plot:=Input("choose
event trend
[1~2]",1,2,1);
choose:=Input("plot:
trendline [1], event
points [2]",1,2,1);
{define events}
time1:=C=HHV(C,21);
time2:=C=LLV(C,21);
time2:=time2 AND
time2<>time1;
{alternative events}
dateA:=Year()=2004 AND
Month()=1;
dateA:=If(LastValue(Cum(dateA))=0,
Year()=LastValue(Year())-1
AND Month()=LastValue(Month()),dateA);
LoValA:=Lowest(ValueWhen(1,dateA,L));
timeA:=dateA AND L=LastValue(LoValA);
dateB:=Year()=2004 AND
Month()=6;
dateB:=If(LastValue(Cum(dateB))=0,
Year()=LastValue(Year())
AND Month()=LastValue(Month()),dateB);
LoValB:=Lowest(ValueWhen(1,dateB,L));
timeB:=dateB AND L=LastValue(LoValB);
timeB:=timeB AND timeB<>timeA;
{choose events}
time1:=If(plot=1,time1,timeA);
time2:=If(plot=1,time2,timeB);
price1:=If(plot=1,C,L);
price2:=If(plot=1,C,L);
{restrict to last
events}
time1:=time1
AND
Cum(time1)=LastValue(Cum(time1));
time2:=time2
AND
Cum(time2)=LastValue(Cum(time2));
{sort events}
t1pds:=LastValue(BarsSince(time1));
t2pds:=LastValue(BarsSince(time2));
x1:=If(t1pds>=t2pds,time1,time2);
x2:=If(t1pds>=t2pds,time2,time1);
y1:=If(t1pds>=t2pds,price1,price2);
y2:=If(t1pds>=t2pds,price2,price1);
{fix coordinates}
y1:=ValueWhen(1,x1,y1);
y2:=LastValue(ValueWhen(1,x2,y2));
b1:=LastValue(BarsSince(x1));
b2:=LastValue(BarsSince(x2));
{trendline definition}
plot:=y1+BarsSince(x1)*(y2-y1)/(b1-b2+.000001);
plot:=Ref(Ref(plot,-b2),b2);{rem
to extend plot}
If(choose=1,plot,time1+time2)
(Go
Top...) |
|
|
|
|
|