MT4 hst格式文件的读取

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值