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

Notification

Icon
Error

Options
Go to last post Go to first unread
rayyiu  
#1 Posted : Saturday, June 16, 2007 9:28:05 AM(UTC)
rayyiu

Rank: Member

Groups: Registered, Registered Users
Joined: 5/25/2007(UTC)
Posts: 10

Hi,

I'm new to Metastock and wish to ask is there any function to get today's year, month and dayofmonth values. What I understand is the functions year(), month() and dayofmonth() return values of last bar which is not necessarily today, am I right?

Thanks and regards,

Raymond

lamkeng  
#2 Posted : Sunday, June 17, 2007 9:32:00 AM(UTC)
lamkeng

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 6/15/2007(UTC)
Posts: 9

Raymond,

Try below;

{ 1 is Jan , 2 is Feb ....6 is June etc}

month = 6 ;

year()=2007;

dayofmonth()=17 ;

from

lamkeng

rayyiu  
#3 Posted : Sunday, June 17, 2007 9:54:34 AM(UTC)
rayyiu

Rank: Member

Groups: Registered, Registered Users
Joined: 5/25/2007(UTC)
Posts: 10

Hi lamkeng,

My concern is that if a security has been suspended from trading since 13/5/2007, then the results will be year()=2007; month()=5; dayofmonth()=13. So if today's date values could be got, I may use Explorer to search for any securities suspended or any data lost from eod download.

Raymond

mstt  
#4 Posted : Sunday, June 17, 2007 2:21:47 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)

Raymond

There are several ways to check the date of the last bar of data. One method that I sometimes use samples the date of the last bar of an index or security that is known to be current. With that information it's easy to check each security in a test or exploration and flag those that do (or do not) have current data. With the code below you'd need to insert a functioning path name for the security and check my quickly typed code syntax.

[code] {Last Date Check} DayRef:=LastValue(Security("C:\....\XAO",DayofMonth())); MonthRef:=LastValue(Security("C:\....\XAO",Month())); YearRef:=LastValue(Security("C:\....\XAO",Month())); LastValue(DayofMonth())=DayRef AND LastValue(Month())=MonthRef AND LastValue(Year())=YearRef; */cose* There are also a number of other ways to achieve the same result, as there are for most MetaStock tasks. Roy MetaStock Tips & Tools

mstt  
#5 Posted : Sunday, June 17, 2007 2:24:27 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)

Raymond

The code box should have been …

[code] {Last Date Check} DayRef:=LastValue(Security("C:\....\XAO",DayofMonth())); MonthRef:=LastValue(Security("C:\....\XAO",Month())); YearRef:=LastValue(Security("C:\....\XAO",Month())); LastValue(DayofMonth())=DayRef AND LastValue(Month())=MonthRef AND LastValue(Year())=YearRef; */close* Roy MetaStock Tips & Tools

mstt  
#6 Posted : Sunday, June 17, 2007 2:26:06 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Just forget the last line of code :-(
rayyiu  
#7 Posted : Sunday, June 17, 2007 5:03:24 PM(UTC)
rayyiu

Rank: Member

Groups: Registered, Registered Users
Joined: 5/25/2007(UTC)
Posts: 10

Thanks mstt, your codes really help. [:)]

Raymond

rayyiu  
#8 Posted : Sunday, June 17, 2007 7:46:44 PM(UTC)
rayyiu

Rank: Member

Groups: Registered, Registered Users
Joined: 5/25/2007(UTC)
Posts: 10

Hi Roy,

I tried your coding but I could not get the result of Security() function as expected. List below is the indicator I used for testing (last trading date of security 060410 =10/04/2006 and last trading date of security 070522 = 22/05/2007):

yref1:=LastValue(Security("G: estData EST\060410",Year()));
mref1:=LastValue(Security("G: estData EST\060410",Month()));
dref1:=LastValue(Security("G: estData EST\060410",DayOfMonth()));
yref2:=LastValue(Security("G: estData EST\070522",Year()));
mref2:=LastValue(Security("G: estData EST\070522",Month()));
dref2:=LastValue(Security("G: estData EST\070522",DayOfMonth()));
date1:=dref1+mref1/100+(yref1-100*Int(yref1/100))/10000;
date2:=dref2+mref2/100+(yref2-100*Int(yref2/100))/10000;
date1;
date2

Same value=15.0607 (last trading date of current security) returned for date1 and date2 but not the reference dates 10.0406 and 22.0507 correspondingly. Please correct me if there is anything wrong in my codings.

Raymond

mstt  
#9 Posted : Monday, June 18, 2007 6:21:15 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)

Hi Raymond

I apologise for my mistake. The code I suggested appears to be flawed in concept because the Security() function will not return a date from a reference security that is later than the last-bar date of the current security.

Here's a method that does work. You'll need the Mark Pyle's GV DLL for this, and it's available in the files section. The procedure is as follows.

1. Open a reference chart and drop the indicator onto it. The indicator plots 3 lines giving day, month and year. These values are now stored as global variables.

2. Delete the indicator (the stored values are retained until MS closes).

3. Run the exploration on the database, folder or portfolio to be tested.

The exploration reports the reference last date in column A, each securities last date in column B, and check for a match in column C. Obviously you can mix and max column code to suit your own particular requirements. I'm a little hesitant to rely on fractional values passing an equality check in the Explorer but you code seems to have worked correctly so far. I'm using MS 9.1 EOD.

Roy

MetaStock Tips & Tools

Code:

 
{Indicator}
 {Store date of reference security's last bar}
D:=DayOfMonth();
M:=Month();
Y:=Year();
D:=ExtFml("GV.SetVar","ScanDay",LastValue(D));
M:=ExtFml("GV.SetVar","ScanMonth",LastValue(M));
Y:=ExtFml("GV.SetVar","ScanYear",LastValue(Y));
D; M;Y;
 
 
{Exploration}
 {Col A: Ref Date}
 {Report reference date}
 {format - DD.MMYY}
RD:=LastValue(ExtFml("GV.GetVar","ScanDay"));
RM:=LastValue(ExtFml("GV.GetVar","ScanMonth"));
RY:=LastValue(ExtFml("GV.GetVar","ScanYear"));
RefDate:=RD+RM/100+(RY-100*Int(RY/100))/10000;
RefDate;
 
 {Col B: Chk Date}
 {Report last date of test securities}
 {format - DD.MMYY}
D:=DayOfMonth();
M:=Month();
Y:=Year();
ChkDate:=D+M/100+(Y-100*Int(Y/100))/10000;
ChkDate;
 
 {Col C: Ref=Chk}
 {Mark test securities with current data}
RD:=LastValue(ExtFml("GV.GetVar","ScanDay")); 
RM:=LastValue(ExtFml("GV.GetVar","ScanMonth"));
RY:=LastValue(ExtFml("GV.GetVar","ScanYear"));
RefDate:=RD+RM/100+(RY-100*Int(RY/100))/10000;
D:=DayOfMonth();
M:=Month();
Y:=Year();
ChkDate:=D+M/100+(Y-100*Int(Y/100))/10000;
RefDate=ChkDate;
 
rayyiu  
#10 Posted : Tuesday, June 19, 2007 10:15:06 AM(UTC)
rayyiu

Rank: Member

Groups: Registered, Registered Users
Joined: 5/25/2007(UTC)
Posts: 10

Hi Roy,

Thanks to your code and also thanks to Mark Pyle's GV.DLL, they are really what I needed.[:)]

Raymond

wabbit  
#11 Posted : Tuesday, June 19, 2007 7:32:57 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)
Guys,

An easier (?) way to do this would be to use Richard Dale's excellent and free Nexus Date Plugin which returns the number of days from yuor computer's system date to the date of the last bar on the chart, see : http://www.tradernexus.com/nexusdate/
rayyiu  
#12 Posted : Wednesday, June 20, 2007 11:02:48 AM(UTC)
rayyiu

Rank: Member

Groups: Registered, Registered Users
Joined: 5/25/2007(UTC)
Posts: 10

Thanks wabbit, NexusDate.dll is wonderful, much simpler. Thanks to Richard Dale's sharing.

But I wonder why lastvalue(security("...",year())) could not return the year of last trading date of the reference security. It seems that the data array returned by the reference security will either be trimmed or padded (with values equal to that of last trading date) to the date of the current security. I wonder whether it is the intention of Metastock or it is a bug in Metastock.

Raymond[:)]

mstt  
#13 Posted : Wednesday, June 20, 2007 2:40:19 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)

Raymond

It appears that this is a limitation of the Security() function. Security() does pad for any data missing from the called security, and it does this by returning the value from the most recent valid bar (I see it as functioning much like ValueWhen() in this respect). However, Security() does not seem capable of projecting forward beyond the last bar of the "host" data array. Odd that LastValue() doesn't help, but that's the way it is.

Roy

MetaStock Tips & Tools

Jose  
#14 Posted : Wednesday, June 20, 2007 6:53:09 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)

Raymond, there is a way around the Security() function's data padding.

It involves taking advantage of the highly unlikely event that a security's OHLC values will repeat on the following trading day:

---8<------------------------------------------------------------

{ Security's OHLC reference }
Op:=Security("G: estData EST\060410",O);
Hi:=Security("G: estData EST\060410",H);
Lo:=Security("G: estData EST\060410",L);
Cl:=Security("G: estData EST\060410",C);

{ Security's trading days }
trade:=Op<>Ref(Op,-1)
AND Hi<>Ref(Hi,-1)
AND Lo<>Ref(Lo,-1)
AND Cl<>Ref(Cl,-1);

{ Day/Month/Year of trading day }
Day:=ValueWhen(1,trade,DayOfMonth());
Mth:=ValueWhen(1,trade,Month());
Yr:=ValueWhen(1,trade,Year());

{ Outputs }
Yr;Mth;Day

---8<------------------------------------------------------------

jose '-)

rayyiu  
#15 Posted : Thursday, June 21, 2007 5:18:04 AM(UTC)
rayyiu

Rank: Member

Groups: Registered, Registered Users
Joined: 5/25/2007(UTC)
Posts: 10

Hi jose,

The sample you gave is only for the reference security whose last trading date is earlier than that of the active security. If the last trading date of the reference security is later than the active security, the extra records in the reference security are trimmed and its last trading date cannot be obtained.

Raymond

Jose  
#16 Posted : Thursday, June 21, 2007 8:13:55 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)
Raymond, just swap the securities around - make the latter symbol your base security. Alternatively, you could subscribe to a quality data service so that you won't need to deal with these basic issues. jose '-)
rayyiu  
#17 Posted : Thursday, June 21, 2007 9:02:38 AM(UTC)
rayyiu

Rank: Member

Groups: Registered, Registered Users
Joined: 5/25/2007(UTC)
Posts: 10

Hi jose,

The initial idea of using the lastvalue(security()) is to get the last trading date from an index and use the date to validate daily eod download and filter out the securities without trading from explorations, but it seems the security() function does not perform as expected.

Anyway, Richard Dale's nexusdate.dll has solved my problem.

Raymond

Jose  
#18 Posted : Thursday, June 21, 2007 9:36:03 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)
rayyiu wrote:
Anyway, Richard Dale's nexusdate.dll has solved my problem.
Richard has solved my problem too. I used to spend hours each week checking & cleaning data, but now that I subscribe to Richard's Premium data I can get on with the real challenge: trading profitably with acceptable risk. jose '-)
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.