.hst file format . . . Old and New (Jan 2014)

Back to topics list  | 1 2 3 To post a new topic, please log in or register
avatar
3
nurettin 2015.09.13 18:15 #
 
RaptorUK:

For clarity for myself, at least, and anyone else that has an interest . . .

[...] 

then the bars array (single-byte justification) . . . total 60 bytes

datetimectm;// bar start time8 bytes
doubleopen;// open price8 bytes
doublehigh;// highest price8 bytes
doublelow;// lowest price8 bytes
doubleclose;// close price8 bytes
longvolume;// tick count8 bytes
intspread;// spread4 bytes
longreal_volume;// real volume8 bytes

I read version 400 with success thanks to your post. The problem is the above spec somehow doesn't work for version 401.

I read 7 * 8 + 4 bytes for each candle data, then I unpack them as Long, 4 * Double, Long, Integer, Long (LD4LIL)  and the ohlc data is garbled for some reason. I tried different endianness (because I'm on mac) but it still reads garbage into the doubles. 

 With version 400 I read 4 + 5 * 8 and unpacked them as Integer, 5 * Double and the numbers were correct.

 edit: it worked, here's the working code: https://gist.github.com/nurettin/e8c77336b91f2c00e302 

avatar
123
maj1es2tic 2015.09.18 02:04 #
 

From the PeriodConverter Script that comes with MetaTrader 4.0 Build 840, the header says it is version 401 and it looks like this:

 

//--- write history file header

   FileWriteInteger(ExtHandle,file_version,LONG_VALUE);

   FileWriteString(ExtHandle,c_copyright,64);

   FileWriteString(ExtHandle,c_symbol,12);

   FileWriteInteger(ExtHandle,i_period,LONG_VALUE);

   FileWriteInteger(ExtHandle,i_digits,LONG_VALUE);

   FileWriteInteger(ExtHandle,0,LONG_VALUE);

   FileWriteInteger(ExtHandle,0,LONG_VALUE);

   FileWriteArray(ExtHandle,i_unused,0,13); 

 

 

Which would come out to 8+64+12+(4*8)+(4*13) = 168 bytes

 

 

avatar
123
maj1es2tic 2015.09.18 02:07 #
 
nurettin:

I read version 400 with success thanks to your post. The problem is the above spec somehow doesn't work for version 401.

I read 7 * 8 + 4 bytes for each candle data, then I unpack them as Long, 4 * Double, Long, Integer, Long (LD4LIL)  and the ohlc data is garbled for some reason. I tried different endianness (because I'm on mac) but it still reads garbage into the doubles. 

 With version 400 I read 4 + 5 * 8 and unpacked them as Integer, 5 * Double and the numbers were correct.

 edit: it worked, here's the working code: https://gist.github.com/nurettin/e8c77336b91f2c00e302 

version 401 uses the MqlRates structure, which looks like this:

 

struct MqlRates
  {
   datetime time;         // Period start time
   double   open;         // Open price
   double   high;         // The highest price of the period
   double   low;          // The lowest price of the period
   double   close;        // Close price
   long     tick_volume;  // Tick volume
   int      spread;       // Spread
   long     real_volume;  // Trade volume

  };

 

(6*8) + 4 + 8 = 60 bytes

 

 

avatar
3
nurettin 2015.09.25 21:05 #
 
maj1es2tic:

version 401 uses the MqlRates structure, which looks like this:

 

struct MqlRates
  {
   datetime time;         // Period start time
   double   open;         // Open price
   double   high;         // The highest price of the period
   double   low;          // The lowest price of the period
   double   close;        // Close price
   long     tick_volume;  // Tick volume
   int      spread;       // Spread
   long     real_volume;  // Trade volume

  };

 

(6*8) + 4 + 8 = 60 bytes

 

 

I created a ruby library called hst for both reading and writing 400 and 401 versions: 

https://rubygems.org/gems/hst 


Back to topics list   | 1 2 3  

To add comments, please log in or register