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

Notification

Icon
Error

Options
Go to last post Go to first unread
RCM  
#1 Posted : Tuesday, February 14, 2006 10:07:43 PM(UTC)
RCM

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 2/14/2006(UTC)
Posts: 9

Hi Would anyone have a formula for an ATR weekly trailing stop? Unfortunately I am still using an old version of Metastock (6.52) Thanks to anyone who can help Mark
konrad  
#2 Posted : Wednesday, February 15, 2006 12:01:50 AM(UTC)
konrad

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 6/6/2005(UTC)
Posts: 424
Location: connecticut,USA

For Long: HHV(H - 2.5*ATR(5),10) For Short: LLV(L + 2.5*ATR(5),10) Furthermore, it may be beneficial to dynamically adjust the number of lookback periods in the HHV() or the LLV() function. or: {Upper Band} Prd1:=Input("ATR Period",1,20,5); Prd2:=Input("Period for Highest High Value",1,20,10); (HHV(LLV(L,Prd1)+ATR(Prd1),Prd2)); {Lower Band} Prd2:=Input("Period for Lowest Low Value",1,20,10); (LLV(HHV(H,Prd1)-ATR(Prd1),Prd2))
RCM  
#3 Posted : Wednesday, February 15, 2006 1:01:26 AM(UTC)
RCM

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 2/14/2006(UTC)
Posts: 9

Thanks for your reply konrad. I guess I should have supplied more information about what I am trying to achieve. I would like test various systems and for the exit criteria I would like to exit on a close below a trailing ATR on a weekly chart. So I guess i would need a formula with a weekly count but not sure how to do it. Any ideas? thanks Mark
StorkBite  
#4 Posted : Wednesday, February 15, 2006 9:35:45 AM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
Hey RCM- Welcome to the forum! I'm not the best person to answer this question, but maybe I can lead you to your own discovery. Right now, our search function on the forum is broken. It makes it hard to look up things that could be helpful. Indirectly, I believe that your question has been answered already. But where is that answer? IMO, Jose Silva has written your code, albeit in peices. Avail: http://www.metastocktools.com/;2) ========================= ---8<--------------------------- { Week's true start & end of week (EOW) vPREVx2} { Confirms EOW signal at start of following week, and signals EOW in retrospect. Signals independent of any missing chart data. For use with highly irregular & sporadic (lots of missing data) daily & intraday charts. Use v2.0 signals for normal (liquid) charts.} { ©Copyright 2002~2005 Jose Silva The grant of this license is for personal use only - no resale or repackaging allowed. All code remains the property of Jose Silva.} { http://www.metastocktools.com } { User input } EOW:=Input("Final week's end: [1]True, [2]Current (dynamic)",1,2,1); { Calendar Week counter } limit:=2000; {do not change limit year} LimLeap:=Frac(limit/4)=0 AND Frac(limit/100)<>0 OR Frac(limit/400)=0; NoCount:=limit*365+Int(limit/4) -Int(limit/100)+Int(limit/400)-LimLeap; leap:=Frac(Year()/4)=0 AND Frac(Year()/100)<>0 OR Frac(Year()/400)=0; y:=Year()*365+Int(Year()/4) -Int(Year()/100)+Int(Year()/400)-NoCount; m:= If(Month()=2,31-leap, If(Month()=3,59, If(Month()=4,90, If(Month()=5,120, If(Month()=6,151, If(Month()=7,181, If(Month()=8,212, If(Month()=9,243, If(Month()=10,273, If(Month()=11,304, If(Month()=12,334, -leap))))))))))); DayNr:=y+m+DayOfMonth(); WkCount:=Int((DayNr-1)/7)+(Year()>=limit); { Week's start signal } WeekStart:=WkCount>Ref(WkCount,-1); { Choice of Static/Dynamic last EOW signal } EOW:=If(EOW=2,Cum(1)=LastValue(Cum(1)), Cum(1)=LastValue(Cum(1)) AND DayOfWeek()=5); { Week's end signal } WeekEnd:=LastValue(Ref(WeekStart,1)+PREV-PREV) OR EOW; { Plot signals in own window } WeekStart;-WeekEnd ---8<--------------------------- [/code:1:a3ed08c323] Code 2: [code:1:a3ed08c323]=================== Weekly SMA of Close =================== ---8<--------------------------- { True weekly Close Simple Moving Average v5.0 } { For daily/intraday charts } { Requires "Week's true Start & End" indicator } { Plot is independent of any missing chart data} { ©Copyright 2002~2005 Jose Silva The grant of this license is for personal use only - no resale or repackaging allowed. All code remains the property of Jose Silva. http://www.metastocktools.com } { User inputs } pds:=Input("Weekly SMA periods",1,520,4); shift:=1+Input("SMA vertical shift %", -100,100,0)/100; EOW:=Input("Final week's end: [1]True, [2]Current (dynamic)",1,2,2); plot:=Input("plot: [1] SMA, [2] Crossover signals",1,2,1); { Choice of Static/Dynamic last EOW signal } EOW:=If(EOW=2,Cum(1)=LastValue(Cum(1)), Cum(1)=LastValue(Cum(1)) AND DayOfWeek()=5); { Reference EOW signals } WkEnd:=EOW OR FmlVar("Week's true Start & End","WEEKEND"); { Week's Close } WkCl:=ValueWhen(1,WkEnd,C); WkCl:=ValueWhen(1,WkCl>0,WkCl); { Weekly SMA } z:=Cum(WkEnd*WkCl); WkSma:=(z-ValueWhen(pds+1,WkEnd,z))/pds; { Vertical shift } WkSma:=WkSma*shift; { Crossover signals } signals:=Cross(C,WkSma)-Cross(WkSma,C); { Plot on price chart } If(plot=2,signals,WkSma) ---8<--------------------------- [/code:1:a3ed08c323] Code 3: [code:1:a3ed08c323]{ 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[/code:1:a3ed08c323]
konrad  
#5 Posted : Wednesday, February 15, 2006 4:54:42 PM(UTC)
konrad

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 6/6/2005(UTC)
Posts: 424
Location: connecticut,USA

Joes have good trailing stop Trailing Stop - ATR Chandelier Exit v2.0 pds:=Input("ATR periods",1,252,10); pds1:=Input("ATR lookback periods",1,252,21); multi:=Input("ATR multiplier",0,10,2.5); plot:=Input("plot: trailing stop=1, Long+Short=2, signals=3",1,3,1); adv:=Input("plot: today's trailing stop=0, tomorrow's stop=1",0,1,0); delay:=Input("Entry and Exit signal delay", 0,5,0); StLong:=HHV(C-multi*ATR(pds),pds1); StShort:=LLV(C+multi*ATR(pds),pds1); stopLong:=If(C<PREV,StLong,Max(StLong,PREV)); stopShort:=If(C>PREV,StShort,Min(StShort,PREV)); In:=Cross(C,Ref(stopShort,-1)); Out:=Cross(Ref(stopLong,-1),C); Init:=Cum(In+Out>-1)=1; InInit:=Cum(In)=1; flag:=BarsSince(Init OR In) < BarsSince(Init OR Out)+InInit; signals:=Ref((InInit AND Alert(InInit=0,2) OR flag AND Alert(flag=0,2)) -(flag=0 AND Alert(flag,2)),-delay); stop:=Ref(If(flag=1,stopLong,stopShort),-1+adv); If(plot=1,stop, If(plot=2,Ref(stopLong,-1+adv),0)); If(plot=1,stop, If(plot=2,Ref(stopShort,-1+adv),signals))
RCM  
#6 Posted : Thursday, February 16, 2006 4:04:18 AM(UTC)
RCM

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 2/14/2006(UTC)
Posts: 9

I can see I need to combine the weekly counter and an ATR indicator (including the one konrad suggested) but I still havent figured out yet how to do that. From Jose's site I will try to play around with different combinations but perhaps if this formula has been posted before maybe I can search for it at a later date. Thanks again for your replies Mark
StorkBite  
#7 Posted : Friday, February 17, 2006 5:37:30 AM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
RCM wrote:
I just realised that perhaps I should have posted this question here. I would like to test an ATR trailing stop on weekly data ie Friday end and in my original post http://forum.equis.com/viewtopic.php?t=3364 konrad and stockman have kindly tried to help me out but I think I just need a little more help to gel the formulas together (Joses weekly counter and ATR trailing stop) - would anyone else know how I could? Thanks Mark[/quote
StorkBite  
#8 Posted : Friday, February 17, 2006 5:39:27 AM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
Hey RCM- Did none of the ideas above work for you? What problems did you encounter?
RCM  
#9 Posted : Monday, February 20, 2006 2:42:08 AM(UTC)
RCM

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 2/14/2006(UTC)
Posts: 9

Hi q stockman I followed what you originally suggested and ploted a weekly SMA and then ploted the ATR formula on top of the SMA but I am still a bit lost where I should substitute a 'P' variable? The indicator I assume would then give an ATR value but I want to run an exploration with an exit binary of a 'close below the weekly ATR' (hence the ATR would need to be trailing stop loss?) Sorry for my confusion but I am not the best of Metastock programmers thanks Mark
StorkBite  
#10 Posted : Monday, February 20, 2006 7:47:26 AM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
RCM- I think I'm confusing myself and you too... I'm only a novice code writer. What I had in mind was to plot a weekly close and calculate the ATR based on that. I suppose that it can be done in different ways, though. The ATR Chandelier Exit code above adds a bit of simplicity to it, but it still isn't simple. BTW, that code is not complete, it lacks the copyright, date, and source availability that was originally included by the author Jose Silva. Also, there have been updates to that code. Apparently, copyright violation is just another thing that doesn't weigh on the wicked; but, I digress. [code:1:140198fa1e]{Note: original concepts by Jose Silva. Avail: www.metastocktools.com} {User Inputs } pds:=Input("ATR periods",1,252,10); { Weekly SMA } EOW:=Cum(1)=LastValue(Cum(1)); { Reference EOW signals } WkEnd:=EOW OR FmlVar("Week's true Start & End","WEEKEND"); { Week's Close } WkCl:=ValueWhen(1,WkEnd,C); WkCl:=ValueWhen(1,WkCl>0,WkCl); { Weekly SMA } z:=Cum(WkEnd*WkCl); WkSma:=(z-ValueWhen(2,WkEnd,z)); { ATR Trailing Stop } StLong:=HHV(WkSma-2.5*Mov(ATR(1),pds,E),21); StShort:=LLV(WkSma+2.5*Mov(ATR(1),pds,E),21); stopLong:=If(WkSma<PREV,StLong,Max(StLong,PREV)); stopShort:=If(WkSma>PREV,StShort,Min(StShort,PREV)); { Trade flags/signals } In:=Cross(WkSma,Ref(stopShort,-1)); Out:=Cross(Ref(stopLong,-1),WkSma); Init:=Cum(IsDefined(In+Out))=1; x:=ValueWhen(1,In-Out<>0 OR Init,In-Out); long:=x=1 AND (Alert(x<>1,2) OR Init); short:=x=-1 AND (Alert(x<>-1,2) OR Init); signals:=long-short; flag:=ValueWhen(1,signals<>0 OR Init,signals); { Switch between Long/Short stops } stop:=Ref(If(flag=1,stopLong,stopShort),-1); { Plot } stop; If(C>=stop,1,-1)[/code:1:140198fa1e] This is sort of what I had in mind (ditching the previous P theory). It has a problem using the ATR(1) reference, I think. Maybe you can look at this and adapt it to what you have in mind. If not, it will probably take a better coder than me to take you to the finish line. p.s. Be sure to check out Roy Larsen's work on multi-timeframe indicators, too. Avail: http://www.metastocktips.co.nz/other_formulas.html
RCM  
#11 Posted : Monday, February 20, 2006 11:16:08 PM(UTC)
RCM

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 2/14/2006(UTC)
Posts: 9

Thanks again q stockman; I will explore again what you have suggested and also take a look at Roy larsons formulas - I will keep you posted what I come up with! thanks again RCM
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.