hst2csv
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <stdexcept>
#include <cstdio>
#include <ctime>
#include "header.h"
#include "mt4.hh"
string _Symbol_;
int _Period_;
string _db_;
string _history_;
string _hstfiles_;
string _csvfiles_;
string _marketinfo_;
string Sym[NR_OF_SYMBOLS];
int Per[NR_OF_PERIODS];
int main()
{
init_mt4();
for(int i=0;i<20;i++)
{
string file_in1=hst_filename(Sym[i]);
string csv_out1=csv_filename(Sym[i], Per[0]);
ifstream binary_file(file_in1.c_str(),ios::binary|ios::in);
if (!binary_file)
{
cerr << "No "+file_in1 << endl;
return -1;
}
//...
ofstream csvfile_out1(csv_out1.c_str());
if (!csvfile_out1)
{
cerr << "No "+csv_out1 << endl;
return -1;
}
csvfile_out1 << "TIME,OPEN,LOW,HIGH,CLOSE,VOLUME"<<endl;
// get length of file:
binary_file.seekg (0, ios::end);
long length = binary_file.tellg();
binary_file.seekg (0, ios::beg);
binary_file.read(reinterpret_cast<char *>(&p_Header),sizeof(HistoryHeader));
cout<<p_Header.version<<endl; // database version
cout<<p_Header.copyright<<endl; // copyright info
cout<<p_Header.symbol<<endl; // symbol name
cout<<p_Header.period<<endl; // symbol timeframe
cout<<p_Header.digits<<endl; // the amount of digits after decimal point in the symbol
cout<<ctime(&p_Header.timesign); // timesign of the database creation
cout<<ctime(&p_Header.last_sync); // the last synchronization time
cout<<p_Header.unused<<endl; // to be used in future
while(! binary_file.eof())
{
binary_file.read(reinterpret_cast<char *>(&p_Data1),sizeof(RateInfo));
csvfile_out1 << p_Data1.ctm << "," << p_Data1.open << "," << p_Data1.low << "," << p_Data1.high << "," << p_Data1.close << "," << p_Data1.vol << endl;
}
binary_file.close();
csvfile_out1.close();
}
return 0;
}