Open a History.hst file in vb6: Possible?

 

It must be... But how?

 

hst file has a header, and then individual records for each bar.

"Period Converter Optimized" has the formats in it.

 
phy:

hst file has a header, and then individual records for each bar.

"Period Converter Optimized" has the formats in it.


Thanks for your response.

I have been brooding over this converter thing, and am at a loss. Are you suggesting that I should open the hst file and save it as a csv file, and then open it in my vb6 app? I can do that.

Are affirming that I can actually open the hst file from within my Visual Basic 6 application, which is what I really want to do?

I cannot figure out how to read the header in vb6.

This is a function I tried:

Private Function OpenMarketArray_Fx() As Long
Dim Version As Integer
Dim CopyWrite As String
Dim Symbol As String
Dim Period As Long
Dim Digits As Long
Dim Zero As Long
'
Dim BarTime As Long
Dim Openn As Double
Dim High As Double
Dim Low As Double
Dim Klose As Double
Dim Volume As Double
'
Dim day As Long
'
Open "C:\Users\Donna\Documents\greegree\FxPro\history\FxPro.com-Demo1\EURUSD1.HST" For Input As #1
Input #1, Version, CopyWrite, Symbol, Period, Digits, Zero, Zero
Do While Not EOF(1)
Input #1, BarTime, Openn, Low, High, Klose, Volume
DateTime(day) = BarTime
Market(day, 0) = Low
Market(day, 1) = High
day = day + 1
Loop
Close #1
OpenMarketArray_Fx = day - 1
End Function

On the right track? Out to lunch? What do you think?

At any rate, thanks for your time.

grr

 

I haven't looked at any kind of BASIC in years...

Seems like you have the right idea, you just have to be sure you are "aligned" with the records as you go into the loop.

Count the number of bytes in the header, make sure you are at the beginning of the first record when you begin looping.

Make sure your record reads are reading the correct number of bytes, too.

 
grrprr:

I have been brooding over this converter thing, and am at a loss. Are you suggesting that I should open the hst file and save it as a csv file, and then open it in my vb6 app? I can do that.

You can read the file directly from VB6 without first needing to convert it to CSV. But you need to use binary access to the file (i.e. Get #1 etc) rather than text access (i.e. Input #1 etc). For example:

Open "C:\mt4\test\history\MyBroker\GBPUSD60.hst" For Binary Access Read Shared As #1

' Header data
Dim lVersion As Long, lPeriod As Long, lDigits As Long   ' N.B. VB6 Long = MQL int, i.e. 4-byte integer
Dim strCopyright As String * 64
Dim strSymbol As String * 12
Dim strSkipEndOfHeader As String * 60


' ------------------------------------------------
' Read the header
' ------------------------------------------------

' Get the header details
Get #1, , lVersion
Get #1, , strCopyright
Get #1, , strSymbol
Get #1, , lPeriod
Get #1, , lDigits
' Skip the remaining 60 bytes of the header
Get #1, , strSkipEndOfHeader


' ------------------------------------------------
' Loop through each individual bar
' ------------------------------------------------

' The rest of the file consists of bar data. Keep reading until the end of the file
Dim lTimestamp As Long, dtBarTime As Date, dOpen As Double, dLow As Double, dHigh As Double, dClose As Double, dVolume As Double
While Not EOF(1)
    Get #1, , lTimestamp
    Get #1, , dOpen
    Get #1, , dLow
    Get #1, , dHigh
    Get #1, , dClose
    Get #1, , dVolume

    ' Convert the Unix-style timestamp to a date
    dtBarTime = DateAdd("s", lTimestamp, #1/1/1970#)
Wend

Close 1

 
phy:

I haven't looked at any kind of BASIC in years...

Seems like you have the right idea, you just have to be sure you are "aligned" with the records as you go into the loop.

Count the number of bytes in the header, make sure you are at the beginning of the first record when you begin looping.

Make sure your record reads are reading the correct number of bytes, too.



Thank you very much for laying it out for me, as this was my first experience of opening a binary file.

Your code seemed to work perfectly, but the data doesn't match what I read using the MetaEditor OpenHistoryFile() funtion; different start of file bar-time; different end of file bar-time; data very close but not matching.

It appeared to be "aligned" and reading correctly... I will go over it again.

In the mean time, I was really quite happy just to open the hst file and get something - Thanks for your help.

grr

 

jjc supplied code, not me...

Study that (above)

 
jjc:

You can read the file directly from VB6 without first needing to convert it to CSV. But you need to use binary access to the file (i.e. Get #1 etc) rather than text access (i.e. Input #1 etc). For example:



Thanks for the code, jjc.

I haven't got it yet, but soon...

 
grrprr:

Your code seemed to work perfectly, but the data doesn't match what I read using the MetaEditor OpenHistoryFile() funtion; different start of file bar-time; different end of file bar-time; data very close but not matching.

Are you sure that you don't have history from multiple brokers/servers, and the one which you're checking from VB6 is different to the one currently being used by MT4? If there were a problem with the code then it would almost certainly report complete nonsense, not a slight difference from the correct data.
 
jjc:
Are you sure that you don't have history from multiple brokers/servers, and the one which you're checking from VB6 is different to the one currently being used by MT4? If there were a problem with the code then it would almost certainly report complete nonsense, not a slight difference from the correct data.

I have no other brokers/servers on my pc.

Regrettably, I made a mistake when writing to file which explains the slight difference.

All the data is now correct except for the bartime.

It begins and ends twelve hours behind (one minute data):

My function, first line: "20/03/2009 5:02:00 PM",1.6228,1.62227,1.62334,1.62334,72

mq4 FileOpenHistory: 2009.03.20 17:02,1.6228,1.62227,1.62334,1.62334,72

The last line returns empty - "01/01/1970",0,0,0,0,0 .

Maybe I should mention that that I have opening the files in the directory\history\broker (not the tester folder), with the understanding that these are the same ones that the MetaEditor FileOpenHistory() function uses. I am presently using MetaEditor to write a csv file on every new-bar, and synchronizing my vb6 application with it, which works fine, but I would like to do it all from vb6.

Unfortunately, these hst files only contain data up to the last bar-time when I down-loaded them – they are not being updated.

Can I go live using vb6 and the history files, or must I paste on to these using the dde, or is there another way?

How does the FileOpenHistory() function do it?

Is there a fix for my bar-time?

Many Thanks,

g

 
grrprr:
It begins and ends twelve hours behind (one minute data):

My function, first line: "20/03/2009 5:02:00 PM",1.6228,1.62227,1.62334,1.62334,72

mq4 FileOpenHistory: 2009.03.20 17:02,1.6228,1.62227,1.62334,1.62334,72

5:02pm is the same as 17:02...