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)
|
No problem Mr Ghost - it's clear now that your intentions were honorable. :)
Thanks Wabbit. I see snippets of my code all over the place, but I don't normally mind this, and even encourage improvements wherever suitable.
My main concern is really commercial sites that claim my code as their own, after stripping the copyright header, and attempt to make $ out of it, directly or otherwise.
Anyway, looking at the 2-year old SafeZone code, I'm sure it can be improved. How about this version:
[code:1:6ed363d1b1]
================================
Trailing Stop - Elder's SafeZone
================================
---8<----------------------------------------
{Dr Alexander Elder's SafeZone trailing stop v3}
{ SafeZone types:
[1] Uses upside/downside penetration days as
suggested by Dr Elder in his book;
[2] Uses up/down days (instead of
upside/downside penetration days)
to match book's companion spreadsheet.}
{ Triggers: Long (+1) & Short (-1) signals at
crossover of user-defined trailing stops.}
{ ©Copyright 2003-2005 Jose Silva }
{ For personal use only }
{ http://www.metastocktools.com }
{ User inputs }
coefficient:=Input("SafeZone coefficient",
0,10,2.5);
bkpds:=Input("Lookback periods",1,260,10);
pds:=Input("Trend EMA periods",2,260,21);
adv:=Input("plot: [1]Today's SafeZone, [2]Tomorrow's stop",1,2,1)-1;
type:=Input("SafeZone type: [1]Book, [2]Spreadsheet",1,2,1);
plot:=Input("SafeZone: [1]Stop, [2]Long+Short, [3]Signals",1,3,1);
{ Downside penetrations }
DwSidePen:=
If(type=1,Mov(C,pds,E)>Ref(Mov(C,pds,E),-1),1)
AND L<Ref(L,-1);
DwSideDiff:=If(DwSidePen,Ref(L,-1)-L,0);
DwPenAvg:=Sum(DwSideDiff,bkpds)
/Max(Sum(DwSidePen,bkpds),.000001);
StLong:=Ref(L-DwPenAvg*coefficient,-1);
StopLong:=If(C<PREV,StLong,Max(StLong,PREV));
{ Upside penetrations }
UpSidePen:=
If(type=1,Mov(C,pds,E)<Ref(Mov(C,pds,E),-1),1)
AND H>Ref(H,-1);
UpSideDiff:=If(UpSidePen,H-Ref(H,-1),0);
UpPenAvg:=Sum(UpSideDiff,bkpds)
/Max(Sum(UpSidePen,bkpds),.000001);
StShort:=Ref(H+UpPenAvg*coefficient,-1);
StopShort:=If(C>PREV,StShort,Min(StShort,PREV));
{ Stop signals }
entry:=Cross(C,Ref(StopShort,-1));
exit:=Cross(Ref(StopLong,-1),C);
{ Clean signals }
Init:=Cum(IsDefined(entry+exit))=1;
bin:=ValueWhen(1,entry-exit<>0 OR Init,
entry-exit);
entry:=bin=1 AND (Alert(bin<>1,2) OR Init);
exit:=bin=-1 AND (Alert(bin<>-1,2) OR Init);
{ Plot on price chart }
If(plot=1,Ref(If(bin=1,stopLong,stopShort),
-1+adv),If(plot=2,Ref(stopLong,-1+adv),0));
If(plot=1,Ref(If(bin=1,stopLong,stopShort),
-1+adv),If(plot=2,Ref(stopShort,-1+adv),
entry-exit))
---8<----------------------------------------
[/code:1:6ed363d1b1]
And I agree, Patrick - imitation and plagiarism can be the sincerest form of flattery... :)
jose '-)
http://www.metastocktools.com
|