You can read the HST file in the same way you write to it. The FileOpenHistory function can be used for writing or for reading. Please reference the link to the documentation.
You can read the HST file in the same way you write to it. The FileOpenHistory function can be used for writing or for reading. Please reference the link to the documentation.
hi, thanks for answering.
my problem is that I don't know how to get the last candle data from that hst file when its converted to Bin format without opening chart.
I think I should get the last pointer position with FileTell(hst-handle)... then use FileReadStruct( at some pointer location )
but the documentation is not clear written.
also I don't want to read whole hst file on every timer ... and convert whole data to candles arrays in memory again, for a simple comparison of only last candle.
in normal conditions , I save the last pointer position , download OHLC data from api again for last candle, and then I update the mqlrate struct from that last saved fpos... so last candle updates or one new candle is being gerenated.
but when there is gaps... I have to update more candles than simply last one by comparing data existing in history.
maybe im confused? how can I get Time[0] from hst file ?
I think I should get the last pointer position with FileTell(hst-handle)... then use FileReadStruct( at some pointer location ). but the documentation is not clear written. also I don't want to read whole hst file on every timer ... and convert whole data to candles arrays in memory again, for a simple comparison of only last candle. in normal conditions , I save the last pointer position , download OHLC data from api again for last candle, and then I update the mqlrate struct from that last saved fpos... so last candle updates or one new candle is being gerenated. but when there is gaps... I have to update more candles than simply last one by comparing data existing in history. maybe im confused? how can I get Time[0] from hst file ?
It is simple math. You know the header size and you know the record size.
There is only one header and multiple records, so ... [Header size] + [Record size] x [number of records] = [File size] (FileSize).
Calculate the [number of records] and then use FileSeek to exactly go to where you need to start reading the last record.
A quicker and simpler way (assuming the file is not corrupted), to knowing the starting position of the last record is simply [File size] - [Record size].
It is simple math. You know the header size and you know the record size.
There is only one header and multiple records, so ... [Header size] + [Record size] x [number of records] = [File size] (FileSize).
Calculate the [number of records] and then use FileSeek to exactly go to where you need to start reading the last record.
A quicker and simpler way (assuming the file is not corrupted), to knowing the starting position of the last record is simply [File size] - [Record size].
great. according to the table in this link for version 401 ... header is 148 bytes.
https://www.mql5.com/en/forum/149178
mqlrates 60 bytes * number of records.
I will test now. thanks.
- 2014.01.29
- www.mql5.com
It is simple math. You know the header size and you know the record size.
There is only one header and multiple records, so ... [Header size] + [Record size] x [number of records] = [File size] (FileSize).
Calculate the [number of records] and then use FileSeek to exactly go to where you need to start reading the last record.
A quicker and simpler way (assuming the file is not corrupted), to knowing the starting position of the last record is simply [File size] - [Record size].
nice point :x
ETHUSD,M15: line:9742 | TF:15m | 64060 record(s) written.| filesize:3843748 Bytes.
(64060*60)+148=3843748 its correct.
now Im going to write the code you suggested and get the candle data and see if I can write it.
thanks again.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hi, I am writing an offline chart in which I get OHLC data from an API.
I convert data to csv and convert the csv to MQLrates and then save it as hst.
this is the first step which is working fine.
now the issue is that sometimes because of network issues or latency or any unknow error there may be a gap in the data, and candles get wrong.
now I want to read the data from the hst file that I create in the first step with FileOpenHistory, and check the last candle data in the history ( without opening the offline chart and read candle 0 data )
and then download OHLC from that latest candle time to the current time from api again and update the hst file.
any suggestions?
I searched and read topics like these but I couldn't fine complete documentation info.
https://www.mql5.com/en/articles/1387