#include <time.h>
#include <afxtempl.h>
#include <afx.h>
#include <iostream>
using namespace std;
#pragma pack(pop) //读取MT4历史数据的范例
typedef struct HistoryHeader
{
int version; // 基础版本
char copyright[64]; // 版权信息
char symbol[12]; // 证券
int period; // 周期类型
int digits; // 小数位数
time_t timesign; // 基础报时的创建
time_t last_sync; // 同步时间
//int unused[13]; // 将来应用
int unused[13];
}MTHSTHEAD;
#pragma pack(push,1)
typedef struct RateInfo
{
//double value1;
//double value2;
//double value3;
long long value4;
unsigned int value5;
double value6;
double value1;
double value2;
double value3;
}MTHST;
typedef struct OffSet
{
double value1;
double value2;
double value3;
}OFFSET;
void TestCArray()
{
CArray<CPoint, CPoint> myArray;
CPoint pt;
// Add elements to the array.
for (int i = 0; i < 10; i++)
myArray.Add(CPoint(i, 2 * i));
// Modify all the points in the array.
for (int i = 0; i <= myArray.GetUpperBound(); i++)
{
pt = myArray.GetAt(i);
pt.x = 0;
myArray.SetAt(i, pt);
}
}
int main(int argc, char* argv[])
{
MTHSTHEAD hsthead;
MTHST kline;
CArray<MTHST, MTHST > akline;
CFile file;
if (file.Open(_T("..//..//history//SILVER1440.hst"), CFile::modeRead))
{
file.SeekToBegin();
file.Read(&hsthead, sizeof(MTHSTHEAD));
//OFFSET offSet;
//file.Read(&offSet, sizeof(OFFSET));
file.Seek(-20, CFile::current);
while (sizeof(MTHST) == file.Read(&kline, sizeof(MTHST)))
{
akline.Add(kline);
}
//char _inBuf[2] = "A";E
//while (1 == file.Read(_inBuf, 1))
//{
// printf("%s", &_inBuf[0]);
// Sleep(100);
//}
file.Close();
}
else
{
printf("failed to open file\n");
}
printf("size of MTHST is %d\n", sizeof(MTHST));
printf("size of OFFSET is %d\n", sizeof(OFFSET));
MTHST _mthst;
for (int i = 0; i < akline.GetUpperBound(); i++)
{
_mthst = akline.GetAt(i);
//cout << _mthst.high << " " << _mthst.low << endl;
printf("%d\t%f\t%f\t%f\t%f\t \n",
/*_mthst.value4, */_mthst.value5, _mthst.value6, _mthst.value1, _mthst.value2, _mthst.value3);
//_mthst.value7, _mthst.value8, _mthst.value9, _mthst.value10, _mthst.value11, _mthst.value12, _mthst.value13);
Sleep(1000);
}
return 0;
}
MT4 hst格式文件的读取
最新推荐文章于 2025-04-16 09:59:20 发布