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

Notification

Icon
Error

Options
Go to last post Go to first unread
frank1301  
#1 Posted : Monday, June 20, 2005 5:37:47 AM(UTC)
frank1301

Rank: Member

Groups: Registered, Registered Users
Joined: 6/20/2005(UTC)
Posts: 10
Location: Perth, Australia

Hi, I am trying to develop an entry signal based on 5/10/15/20 day exits. It should be quite simple but I am running into problems. The entry signal for instance is C>Mov(C,10,S) and C>Mov(C,20,S). What exit formula would I use in order to exit after 5 days? I tried BarsSince(C>Mov(C,10,S) and C>Mov(C,20,S))=5 but it doesn't work. The formula recounts everytime the entry signal becomes true. I hope someone can help me. ](*,) Frank
wabbit  
#2 Posted : Monday, June 20, 2005 11:30:58 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)
Try: {Roy Larsen's latch} Delay:=5; N:=C>Mov(C,10,S) AND C>Mov(C,20,S); N:=N AND Alert(N=0,2); X:=BarsSince(N)=Delay; Tr:=If(N,1,If(X,0,PREV)); Tr; Hope this helps. wabbit :D [edit] Slightly shorter form of the same thing: {Roy Larsen's latch} Delay:=5; N:=C>Mov(C,10,S) AND C>Mov(C,20,S); N:=N AND Alert(N=0,2); Tr:=If(N,1,If(BarsSince(N)=Delay,0,PREV)); Tr; Take your pick. Same thing.
frank1301  
#3 Posted : Monday, June 20, 2005 12:18:00 PM(UTC)
frank1301

Rank: Member

Groups: Registered, Registered Users
Joined: 6/20/2005(UTC)
Posts: 10
Location: Perth, Australia

Thanks for that. Much appreciated. :P
frank1301  
#4 Posted : Monday, June 20, 2005 1:36:41 PM(UTC)
frank1301

Rank: Member

Groups: Registered, Registered Users
Joined: 6/20/2005(UTC)
Posts: 10
Location: Perth, Australia

Hello Wabbit I just tried the latch formula on the system tester but the length of the trades were not consistently 5 bars. Do you have any other suggestions? Cheers :?:
wabbit  
#5 Posted : Monday, June 20, 2005 1:49:33 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)
The code as is will open a trade if the criteria is met, it will exit the trade five days later if, and only if, the criteria is not met again during the five days. If you only want to initiate a trade and leave it open for five days, regardless of what happens with respect to your criteria, then try this: Delay:=5; N:=C>Mov(C,10,S) AND C>Mov(C,20,S); N:=N AND Alert(N=0,2); Tr:=If(PREV=0,N,BarsSince(PREV=0)<=Delay); Tr; Hope this helps, this time. wabbit :D P.S. Where in Perth are you. Me SOR.
frank1301  
#6 Posted : Monday, June 20, 2005 2:28:53 PM(UTC)
frank1301

Rank: Member

Groups: Registered, Registered Users
Joined: 6/20/2005(UTC)
Posts: 10
Location: Perth, Australia

Thanks wabbit. Unfortunately, I still have problems with the code. The systemtester doesn't consistently exit after 5 bars. If it's easier I can contact you via email or phone. I am in Scarborough.
wabbit  
#7 Posted : Monday, June 20, 2005 2:44:21 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)
what code are you using in the tester as the entry, and as the exit? How long are each of the trades? Can you duplicate the trades on that specific stock using the code as an indicator? System Tester Entry should be: tr=1 and alert(tr=0,2) Exit should be: tr=0 and alert(tr=1,2) Set the delays at zero and see how that goes. Right now though, I am off to bed! If you are still working tonight (Monday night) post any further problems - I may have a brief opportunity to have a look for you tomorrow morning - else someone else here might help out too! wabbit :D
frank1301  
#8 Posted : Wednesday, June 22, 2005 4:27:57 AM(UTC)
frank1301

Rank: Member

Groups: Registered, Registered Users
Joined: 6/20/2005(UTC)
Posts: 10
Location: Perth, Australia

Thanks wabbit. You have been a great help. It's working fine and I guess I have to do some "latching" homework. Are you aware of any Metastock Groups in Perth? I am very interested to catch up. Cheers Frank
edwin4400  
#9 Posted : Wednesday, June 22, 2005 8:02:16 AM(UTC)
edwin4400

Rank: Member

Groups: Registered, Registered Users
Joined: 6/22/2005(UTC)
Posts: 29
Location: Singapore

Hi, I need a formula to count number of trading days within a month (meaning that the counter will reset with a fresh month) to study seasonality. However, the function DayOfMonth() only returns the dates instead of true trading day. Anyone can help? Thanks, edwin
wabbit  
#10 Posted : Wednesday, June 22, 2005 11:41:29 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)
Try this: thisMonth:=LastValue(Month()); LastValue(BarsSince(Month()<>thisMonth)) UNTESTED CODE - but you get the message? wabbit :D
edwin4400  
#11 Posted : Wednesday, June 22, 2005 1:12:08 PM(UTC)
edwin4400

Rank: Member

Groups: Registered, Registered Users
Joined: 6/22/2005(UTC)
Posts: 29
Location: Singapore

Hi Wabbit, thanks for your reply. I am very new to the metastock programming language. I tried out the formula thisMonth:=LastValue(Month()); BarsSince(Month()<>thisMonth) which only plots the trading days only for June period. I tried your idea but make some changes and it works! If(Month()=1,BarsSince(Month()<>1), If(Month()=2,BarsSince(Month()<>2), If(Month()=3,BarsSince(Month()<>3), If(Month()=4,BarsSince(Month()<>4), If(Month()=5,BarsSince(Month()<>5), If(Month()=6,BarsSince(Month()<>6), If(Month()=7,BarsSince(Month()<>7), If(Month()=8,BarsSince(Month()<>8), If(Month()=9,BarsSince(Month()<>9), If(Month()=10,BarsSince(Month()<>10), If(Month()=11,BarsSince(Month()<>11), If(Month()=12,BarsSince(Month()<>12),0)))))))))))) Thanks for your help and pointers, Edwin :D
wabbit  
#12 Posted : Wednesday, June 22, 2005 1:38:53 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)
I was sort of the opinion you were only looking for the lastvalues, sorry. This might save a little of coding and error checking???? lastmonth:=Ref(month(),-1); barsSince(lastmonth<>month()) [Now tested - working!] Hope it helps. wabbit :D
wabbit  
#13 Posted : Wednesday, June 22, 2005 2:13:06 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)
frank1301 wrote:
Are you aware of any Metastock Groups in Perth? I am very interested to catch up.
See http://forum.equis.com/viewtopic.php?p=3581#3581 wabbit :D
edwin4400  
#14 Posted : Thursday, June 23, 2005 5:16:13 AM(UTC)
edwin4400

Rank: Member

Groups: Registered, Registered Users
Joined: 6/22/2005(UTC)
Posts: 29
Location: Singapore

Hi Wabbit, Something amiss with the simpler formula u provided on TDOM. It gives zero count on the first trading day of each month. I cant figure out so I guess i will stick to the long formula i posted earlier. Thanks, Edwin
wabbit  
#15 Posted : Thursday, June 23, 2005 11:04:30 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)
Solved: lastmonth:=Ref(month(),-1); barsSince(lastmonth<>month())+1 The problem is that the day the condition is true BarsSince()=0 byt when we count (unless you are a computer programmer) then the first day is 1 not 0. Hope this helps. wabbit :D P.S. To prove the difference between the formulas, plot this: edwin:=If(Month()=1,BarsSince(Month()<>1), If(Month()=2,BarsSince(Month()<>2), If(Month()=3,BarsSince(Month()<>3), If(Month()=4,BarsSince(Month()<>4), If(Month()=5,BarsSince(Month()<>5), If(Month()=6,BarsSince(Month()<>6), If(Month()=7,BarsSince(Month()<>7), If(Month()=8,BarsSince(Month()<>8), If(Month()=9,BarsSince(Month()<>9), If(Month()=10,BarsSince(Month()<>10), If(Month()=11,BarsSince(Month()<>11), If(Month()=12,BarsSince(Month()<>12),0)))))))))))); lastmonth:=Ref(Month(),-1); wabbit:=BarsSince(lastmonth<>Month()) +1; edwin-wabbit It should be zero, across the board
edwin4400  
#16 Posted : Thursday, June 23, 2005 11:39:47 AM(UTC)
edwin4400

Rank: Member

Groups: Registered, Registered Users
Joined: 6/22/2005(UTC)
Posts: 29
Location: Singapore

Hi Wabbit, Thanks for tip!! It works!!! Wabbit is good wabbit is wise. Thanks, Edwin
edwin4400  
#17 Posted : Thursday, June 23, 2005 12:23:36 PM(UTC)
edwin4400

Rank: Member

Groups: Registered, Registered Users
Joined: 6/22/2005(UTC)
Posts: 29
Location: Singapore

Hi, I am trying out a system test using only long entry. However, I need to exit on the same day close. How can I code this? I have tried limit, stop and stop limit order with "ref(c,-1) but it doesnt work. Please help. Edwin
wabbit  
#18 Posted : Thursday, June 23, 2005 12:57:00 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)
Edwin, I dont use the system tester that much so I cannot really help here, but I have posted an excellent article by Tom Sprunger that might help you in your endeavours. See: http://forum.equis.com/viewtopic.php?p=3636 I suggest you have a look at the article, the in-built help functions and the MS manual. wabbit :D
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.