logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
theghost  
#1 Posted : Tuesday, May 24, 2005 7:34:35 AM(UTC)
theghost

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/4/2005(UTC)
Posts: 63
Location: Poole Dorset England

Here's the formula for Dr. Alexander Elder's Safety Zone. (Trailing Stop). It is good. A lot tighter than Chandelier Stops, but far enough away from market noise. Enjoy. MetaStock -> Tools -> Indicator Builder -> New Copy and paste formula below. coefficient:=Input("SafeZone coefficient", 0,10,2.5); bkpds:=Input("Lookback periods",1,252,10); pds:=Input("Trend EMA periods",2,252,21); adv:=Input("plot: today's SafeZone=0, tomorrow's stop=1",0,1,0); plot:=Input("plot: trailing stop=1, Long+Short=2, signals=3",1,3,1); delay:=Input("Entry and Exit signal delay", 0,5,0); DwSidePen:=Mov(C,pds,E)>Ref(Mov(C,pds,E),-1) AND L<Ref(L,-1); DwSideDiff:=If(DwSidePen,Ref(L,-1)-L,0); DwPenAvg:=Sum(DwSideDiff,bkpds) /(Sum(DwSidePen,bkpds)+.000001); StLong:=Ref(L-DwPenAvg*coefficient,-1); StopLong:=If(C<PREV,StLong,Max(StLong,PREV)); UpSidePen:=Mov(C,pds,E)<Ref(Mov(C,pds,E),-1) AND H>Ref(H,-1); UpSideDiff:=If(UpSidePen,H-Ref(H,-1),0); UpPenAvg:=Sum(UpSideDiff,bkpds) /(Sum(UpSidePen,bkpds)+.000001); StShort:=Ref(H+UpPenAvg*coefficient,-1); StopShort:=If(C>PREV,StShort,Min(StShort,PREV)); In:=Cross(C,Ref(StopShort,-1)); Out:=Cross(Ref(StopLong,-1),C); flag:=BarsSince(Cum(In+Out>-1)=1 OR In) < BarsSince(Cum(In+Out>-1)=1 OR Out) +(Cum(In)=1); signals:=Ref((Cum(In)=1 AND Alert((Cum(In)=1)=0,2) OR flag AND Alert(flag=0,2)) -(flag=0 AND Alert(flag,2)),-delay); If(plot=1,Ref(If(flag=1,stopLong,stopShort), -1+adv),If(plot=2,Ref(stopLong,-1+adv),0)); If(plot=1,Ref(If(flag=1,stopLong,stopShort), -1+adv),If(plot=2,Ref(stopShort,-1+adv), signals))
Jose  
#2 Posted : Tuesday, May 24, 2005 11:27:21 AM(UTC)
Jose

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)
Mr Ghost, if you are willing to post copyright material on the Net, please do not remove the copyright header. :evil: The original and full MetaStock code is here: http://www.metastocktool...m/MetaStock/SafeZone.txt MetaStock -> Tools -> Indicator Builder -> New Copy and paste formula below. [code:1:6f116846ac] ================================ Trailing Stop - Elder's SafeZone ================================ ---8<---------------------------------------- { Dr Alexander Elder's SafeZone trailing stop v2 } { Triggers: Long (+1) & Short (-1) signals at crossover of user-defined trailing stops } { ©Copyright 2003 Jose Silva } { http://www.metastocktools.com } coefficient:=Input("SafeZone coefficient", 0,10,2.5); bkpds:=Input("Lookback periods",1,252,10); pds:=Input("Trend EMA periods",2,252,21); adv:=Input("plot: today's SafeZone=0, tomorrow's stop=1",0,1,0); plot:=Input("plot: trailing stop=1, Long+Short=2, signals=3",1,3,1); delay:=Input("Entry and Exit signal delay", 0,5,0); DwSidePen:=Mov(C,pds,E)>Ref(Mov(C,pds,E),-1) AND L<Ref(L,-1); DwSideDiff:=If(DwSidePen,Ref(L,-1)-L,0); DwPenAvg:=Sum(DwSideDiff,bkpds) /(Sum(DwSidePen,bkpds)+.000001); StLong:=Ref(L-DwPenAvg*coefficient,-1); StopLong:=If(C<PREV,StLong,Max(StLong,PREV)); UpSidePen:=Mov(C,pds,E)<Ref(Mov(C,pds,E),-1) AND H>Ref(H,-1); UpSideDiff:=If(UpSidePen,H-Ref(H,-1),0); UpPenAvg:=Sum(UpSideDiff,bkpds) /(Sum(UpSidePen,bkpds)+.000001); StShort:=Ref(H+UpPenAvg*coefficient,-1); StopShort:=If(C>PREV,StShort,Min(StShort,PREV)); In:=Cross(C,Ref(StopShort,-1)); Out:=Cross(Ref(StopLong,-1),C); flag:=BarsSince(Cum(In+Out>-1)=1 OR In) < BarsSince(Cum(In+Out>-1)=1 OR Out) +(Cum(In)=1); signals:=Ref((Cum(In)=1 AND Alert((Cum(In)=1)=0,2) OR flag AND Alert(flag=0,2)) -(flag=0 AND Alert(flag,2)),-delay); If(plot=1,Ref(If(flag=1,stopLong,stopShort), -1+adv),If(plot=2,Ref(stopLong,-1+adv),0)); If(plot=1,Ref(If(flag=1,stopLong,stopShort), -1+adv),If(plot=2,Ref(stopShort,-1+adv), signals)) ---8<---------------------------------------- [/code:1:6f116846ac] jose '-) http://www.metastocktools.com
wabbit  
#3 Posted : Tuesday, May 24, 2005 12:12:02 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Jose, I have recently seen, what I believe to be, your code all over the place. I hadn't really been keeping track of the URLs where, but I will from now and let you know who is claiming your work as their own. There were a couple of .ru sites and if I remember correctly, one in the US. The sites themselves werent very good, so I didnt bookmark them and havent been back to vist since. wabbit :D
theghost  
#4 Posted : Tuesday, May 24, 2005 12:29:42 PM(UTC)
theghost

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/4/2005(UTC)
Posts: 63
Location: Poole Dorset England

Apologies are due, But a genuine mistake I assure you. This was forwarded to me by a friend in Singapore as we were speaking about Elders book as I have read just read "Come Into My Trading Room" (And saw his excel spreadsheet alternative etc to the code).He forwarded it to me. The internet is so huge, and downloading, or copy and pasting is so easy without even thinking about copywrite issues etc. Is this your code then? I am a rookie, can't program for toffee's so don't think I was trying to make this sound as if I programmed it, because I wouldn't. I just thought it would help as I noticed a post about the Elder on here. Once again apologies. If it needs to be removed then so be it. It is a genuine mistake If this is yours, well, well done mate, it is a novel and new way at approaching the stop loss issue Sorry once again Theghost
Patrick  
#5 Posted : Tuesday, May 24, 2005 2:26:35 PM(UTC)
Patrick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/8/2004(UTC)
Posts: 2,266

Was thanked: 1 time(s) in 1 post(s)
Jose, You should be flattered that your work is making it around the globe at lightspeed :wink: It's what we call in french ( I don't know if this translates well ) "the ransom of glory" Patrick :mrgreen:
Jose  
#6 Posted : Tuesday, May 24, 2005 2:57:45 PM(UTC)
Jose

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
Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.