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

Notification

Icon
Error

Options
Go to last post Go to first unread
TonyPH  
#1 Posted : Wednesday, June 8, 2005 11:26:21 AM(UTC)
TonyPH

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 6/8/2005(UTC)
Posts: 3
Location: Sydney Australia

Wondering if someone with a little more experience in the formula language could help, I’ve written the following for an non returning ATR based trailing stop and this seems to work as desired; Period:=Input("ATR Average Period",3,100,20); ATRM:=Input("ATR Multiple",1,10,2.5); Stop:=C-ATRM*ATR(Period); If(L<=PREV,PREV, If(Stop>PREV,Stop,PREV)); Would now like to be able to specify the date the ATR starts from, I know the following can be added so it prompts for the date input; Day1:= Input("Day of Month" ,1,31,5); Month1:= Input("Month" ,1,12,1); Year1:= Input("Year",2000,2010,2005); But I am not sure then how to get the ATR formula to start from the specified date, any advice welcome, Tony
wabbit  
#2 Posted : Wednesday, June 8, 2005 11:56:09 AM(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)
Can I suggest you have a look at Richard Dale's excellent (and free) advanced trailing stop. Its volatility based (ATR) and is available from: http://www.tradernexus.c...edstop/advancedstop.html On the question of dates: [Edited formula - last one generated ome error???] fmDate:=Input("Start ddmmyy (0=first trade)",0,311299,0); fmDay:=If(fmDate=0,ValueWhen(1,Cum(1)=1,DayOfMonth()),Int(fmDate/10000)); fmMonth:=If(fmDate=0,ValueWhen(1,Cum(1)=1,Month()),Int((fmDate-fmDay*10000)/100)); fmYear:=If(fmDate=0,ValueWhen(1,Cum(1)=1,Year()),Int(fmDate-Int(fmDate/100)*100)); fmYear:=If(fmYear<100,If(fmYear<40,fmYear+2000,fmYear+1900),fmYear); ((DayOfMonth()>=fmDay AND Month()=fmMonth AND Year()=fmYear) OR (Month()>fmMonth AND Year()=fmYear) OR Year()>fmYear); will return TRUE (1) on and after the start date. If you enter 0 for the date, the start date is the first bar in the chart. Hope this helps. wabbit :D
TonyPH  
#3 Posted : Friday, June 10, 2005 3:28:42 AM(UTC)
TonyPH

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 6/8/2005(UTC)
Posts: 3
Location: Sydney Australia

Thanks wabbit, the Stops on Trader Nexus are as you say excellent and that's what I'lll use, still couldn't get the dates figured out from what you posted below but not to worry now, appreciate your help Tony
wabbit  
#4 Posted : Friday, June 10, 2005 5:40:55 AM(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)
Never let a computer win! What part(s) didnt you understand? fmDate:=Input("Start ddmmyy (0=first trade)",0,311299,0); This bit should be OK. The use inputs the date in the format ddmmyy, or enters 0 for the date to be the date of the first bar in the chart. fmDay:=If(fmDate=0,ValueWhen(1,Cum(1)=1,DayOfMonth()),Int(fmDate/10000)); This bit of code says: if the user entered zero then find the DayofMonth() of the first bar in the chart (Cum(1)=1). If the user didnt enter zero, and entered a date in the proper format, divide the number representing the date, ignore everything to right of the decimal point and the resulting number should be the user entered value for DayofMonth(). A similar process happens to extract the month and year from the user input. fmMonth:=If(fmDate=0,ValueWhen(1,Cum(1)=1,Month()),Int((fmDate-fmDay*10000)/100)); fmYear:=If(fmDate=0,ValueWhen(1,Cum(1)=1,Year()),Int(fmDate-Int(fmDate/100)*100)); fmYear:=If(fmYear<100,If(fmYear<40,fmYear+2000,fmYear+1900),fmYear); This bit just formats years greater than 40 as 1900+year, eg 1989 and years less than 40 as 2000+year e.g 2004 Notice the reuse of the fmYear variable. ((DayOfMonth()>=fmDay AND Month()=fmMonth AND Year()=fmYear) OR (Month()>fmMonth AND Year()=fmYear) OR Year()>fmYear); This is where the trickery takes place. It finds the first bar where the day and month and year criteria are met. This of course only happens if the stock traded that day, otherwise it finds the bar when the month and year criteria are met if the stock traded that month, otherwise it finds the bar when the year criteria is met. Hopefully this explanation will help you understand this code a little better. Please dont take other people's code or answers for granted. If you dont understand something please ask. Sometimes it is a little difficult to explain things, but if you dont understand the answer then we have not answered the question at all. Hope this helps. wabbit :D
TonyPH  
#5 Posted : Tuesday, June 14, 2005 1:56:43 AM(UTC)
TonyPH

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 6/8/2005(UTC)
Posts: 3
Location: Sydney Australia

Got it, understand the date logic now and I am getting a binary wave when I plot it, however I am still struggling how to build it into my ATR Trailing Stop formula, this is what I have; fmDate:=Input("Start ddmmyy (0=first trade)",0,311299,0); fmDay:=If(fmDate=0,ValueWhen(1,Cum(1)=1,DayOfMonth()),Int(fmDate/10000)); fmMonth:=If(fmDate=0,ValueWhen(1,Cum(1)=1,Month()),Int((fmDate-fmDay*10000)/100)); fmYear:=If(fmDate=0,ValueWhen(1,Cum(1)=1,Year()),Int(fmDate-Int(fmDate/100)*100)); fmYear:=If(fmYear<100,If(fmYear<40,fmYear+2000,fmYear+1900),fmYear); fm:=((DayOfMonth()>=fmDay AND Month()=fmMonth AND Year()=fmYear) OR (Month()>fmMonth AND Year()=fmYear) OR Year()>fmYear); Period:=Input("ATR Average Period",3,100,20); ATRM:=Input("ATR Multiple",1,10,2.5); Stop:=C-ATRM*ATR(Period); If(fm=1,If(L<=PREV,PREV, If(Stop>PREV,Stop,PREV)),0); It works in that it plots the Trailing Stop from the specified date however with the way I’ve put the formula together it also plots “0” (or whatever number is stated as the False option) prior to the specified date, is there anyway to get it to plot “blank” if not True, in Excel I would use "" but that don’t work in Metastock, I looked through the Formula Primer but still could see how to resolve………………sorry
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.