Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Metastock data file format

701 views
Skip to first unread message

Fred Walter

unread,
Apr 27, 1992, 11:30:29 AM4/27/92
to
A while back I asked what the Metastock data file format was. Since some
people expressed interest in my findings, here is what I found out :

::::::::::::::
Metastock data files are in Computrac Format. Within the directory there is a
file called MASTER which contains the symbol names and file numbers for the
data files, called Fn.DAT (where n={1..255}).
::::::::::::::
Following is the format for the Metastock 2.5 MASTER file.
It is a segment of a program I wrote in C. I hope it is
understandable. Each record in the master is 53 bytes. There
is a header record and then a record for each stock.

/* MASTER FILE HEADER RECORD */

struct mspheader
{
unsigned char numberofsymbols;
char filler1;
unsigned char lastfnumber;
char filler2;
char fillstring[49];
} masterhead;

/* MASTER FILE RECORD FOR EACH SYMBOL */

struct mspmasterrec
{
unsigned char rec_a; /* F# of Symbol */
int rec_b; /* 00h 00h */
char rec_c; /* Number of Fields * 4 (hex)*/
char rec_d; /* Number of Fields (hex) */
int rec_ef; /* 00h 00h */
char rec_g[16]; /* Name */
int rec_h; /* 00h 00h */
float rec_i; /* Start Date YYMMDD */
float rec_j; /* Last Date YYMMDD */
char rec_k; /* D = daily W = weekly */
int rec_l; /* 00h 00h */
char rec_m[16]; /* Symbol */
char rec_n; /* Filler */
} masterr;

The DAT file for a 5 field stock consists of a header record
followed by a record for each day (or week, or month) of data.
Each record is 20 bytes long. The order of the data is: Date,
High, Low, Close, Volume. The date is in the format of YYMMDD
and is a floating point number, not a string.

/* F?.DAT FILE FOR A FIVE FIELD SYMBOL */

struct mspfiveheader
{
int dummy; /* Filler */
int records; /* NUMBER OF RECORDS */
float recordef[4]; /* Filler */
} fiveheader;

struct mspfive
{
float field[5];
} five;

/* END OF VARIABLE DECLARATIONS */
::::::::::::::
The Metastock data files are in the "old" BASIC random access
file format, aka the Microsoft Binary format. Microsoft BASIC
and Quick Basic now use the IEEE format.

If you were writing in Microsoft BASIC or Quick Basic, the
Function to convert a Microsoft Binary format 4-byte-string to a
single precision number is CVSMBF. In the .DAT files, the first
20 byte record can be discarded. The remaining 20 byte strings
are parsed into five 4-byte-strings until EOF. The four byte
sub-strings are date (YYMMDD), high, low, close, volume.

The MASTER file contains the information about the .DAT
files, It is also in Microsoft Binary format.

The Metastock Utilities Manual (Section 9.2) goes into some
detail about what is in both the MASTER file and .DAT files, and
how to extract the information using BASIC. However, in their
illustration, they use CVS as the Function. That will work for
old issues of BASIC. For BASIC using IEEE, you need to use the
CVSMBF Function instead of the CVS function.

If you can't use a function, it is possible to extract the
numbers from the file by using the ASCII values of the four byte
segments, byte by byte. There is a fairly complicated set of
rules whereby one of the bytes sets the decimal place, one is
multiplied by another, and another is subtracted. You can then
set up your own Function. I used this technique years ago before
I discovered CVSMBF. I don't remember the procedure, but it can
be ascertained by looking at the values and the actual byte ASCII
equivalents. It is slower than using CVSMBF.

--
Disclaimer: everything I post is my *personal* opinion and does not represent
or reflect the opinion of the company which employs me.

0 new messages