For clarity for myself, at least, and anyone else that has an interest . . .
then the bars array (single-byte justification) . . . total 60 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
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
Which would come out to 8+64+12+(4*8)+(4*13) = 168 bytes
version 401 uses the MqlRates structure, which looks like this:
(6*8) + 4 + 8 = 60 bytes
I created a ruby library called hst for both reading and writing 400 and 401 versions: