#property copyright "Copyright 2013, Evgeniy Trofimov"
#property link ""
#property show_inputs
extern string FileName = "FUTURE_NGJ1991"; //Èìÿ ôàéëà áåç ðàñøèðåíèÿ ñêà÷àííîãî ñ ñàéòà http://www.quandl.com
extern int SymbolDigits = 5;
#include <WinUser32.mqh>
//+----------------------------------------------------------------------------+
void start(){
string aTime[];
double aOpen[];
double aHigh[];
double aLow[];
double aClose[];
int aVolume[];
int aCount=0;
int pos=0;
string temp;
int hRead=0, hWrite=0; //Óêàçàòåëè îòêðûòûõ ôàéëîâ
datetime LastDate=0; //Äàòà ýêñïèðàöèè ïðîøëîãîäíåãî êîíòðàêòà
datetime CurDate=0; //Òåêóùàÿ îáðàáàòûâàåìàÿ äàòà
datetime FirstDate=0; //Ïåðâàÿ äàòà â ôàéëå ôüþ÷åðñà (äàòà ýêñïèðàöèè)
bool FirstTimeFutures=false; //Ôëàã òîãî, ÷òî ñ÷èòûâàåòñÿ ïåðâàÿ ñòðîêà ñ ôàéëà ôüþ÷åðñà
string FilePrefix = StringSubstr(FileName, 0, StringLen(FileName)-4);
int BeginYear = StrToDouble(StringSubstr(FileName, StringLen(FileName)-4));
//Alert("FilePrefix = ", FilePrefix, ", BeginYear = ", BeginYear);
hWrite=FileOpen(FilePrefix+".csv",FILE_CSV|FILE_WRITE,',');
for(int y = BeginYear; y <= Year(); y++){
//======== ×ÒÅÍÈÅ =======
hRead=FileOpen(FilePrefix+DoubleToStr(y,0)+".csv",FILE_CSV|FILE_READ,',');
if(hRead<0) {
Alert("Ïðè îòêðûòèè ôàéëà ", FilePrefix+DoubleToStr(y,0)+".csv", " âîçíèêëà îøèáêà ", GetLastError());
continue;
} else {
FileSeek(hRead,47,SEEK_SET); //Ïðîïóñê øàïêè (47 ñèìâîëîâ)
if(FileSize(hRead)>47){
FirstTimeFutures=true;
while(pos<FileSize(hRead)){
temp = FileReadString(hRead);
temp = StringSubstr(temp,0,4)+"."+StringSubstr(temp,5,2)+"."+StringSubstr(temp,8,2);
CurDate = StrToTime(temp);
if(FirstTimeFutures){
FirstTimeFutures=false;
FirstDate=CurDate;
}
if(CurDate<=LastDate){
break;
}
aCount++;
ArrayResize(aTime, aCount);
aTime[aCount-1]=temp;
ArrayResize(aOpen, aCount);
aOpen[aCount-1]=StrToDouble(FileReadString(hRead));
ArrayResize(aHigh, aCount);
aHigh[aCount-1]=StrToDouble(FileReadString(hRead));
ArrayResize(aLow, aCount);
aLow[aCount-1]=StrToDouble(FileReadString(hRead));
ArrayResize(aClose, aCount);
aClose[aCount-1]=StrToDouble(FileReadString(hRead)); //Settle
//temp = FileReadString(hRead); //Çäåñü ïðîïóñêàåì öåíó Settle
ArrayResize(aVolume, aCount);
aVolume[aCount-1]=StrToInteger(FileReadString(hRead));
temp = FileReadString(hRead); //Çäåñü ïðîïóñêàåì Open Interest
pos=FileTell(hRead);
}//End While
LastDate=FirstDate;
}
FileClose(hRead);
}
//======== ÇÀÏÈÑÜ =======
temp = DoubleToStr(aOpen[aCount-2], SymbolDigits);
for(pos = aCount-1; pos >= 0; pos--){
if(aClose[pos]<0.0000001) continue;
if(aOpen[pos]<0.0000001) aOpen[pos]=aClose[pos];
if(aHigh[pos]<0.0000001) aHigh[pos]=aClose[pos];
if(aLow[pos]<0.0000001) aLow[pos]=aClose[pos];
FileWrite(hWrite,
aTime[pos]+",00:00",
DoubleToStr(aOpen[pos], SymbolDigits),
DoubleToStr(aHigh[pos], SymbolDigits),
DoubleToStr(aLow[pos], SymbolDigits),
DoubleToStr(aClose[pos], SymbolDigits),
/*temp,*/
DoubleToStr(aVolume[pos], 0)
);
//if(pos>1) temp = DoubleToStr(aOpen[pos-2], SymbolDigits);
}//Next pos
aCount=0;
}//Next y
FileClose(hWrite);
MessageBox("Êîíâåðòàöèÿ çàâåðøåíà");
}//start()
//+----------------------------------------------------------------------------+
Comments