#property copyright "Copyright 2012, Evgeniy Trofimov"
#property link ""
#property show_inputs
extern string InputFileName = "Quandl.csv";
extern string OutputFileName = "MT4.csv";
extern int SymbolDigits = 2;
//+----------------------------------------------------------------------------+
void start(){
string hTime[];
double hOpen[];
double hHigh[];
double hLow[];
int hVolume[];
int hCount=0;
int handle=FileOpen(InputFileName,FILE_CSV|FILE_READ,',');
int pos=0;
string temp;
//======== ×ÒÅÍÈÅ =======
if(handle<0) {
Alert("Ïðè îòêðûòèè ôàéëà ", InputFileName, " âîçíèêëà îøèáêà ", GetLastError());
return;
} else {
FileSeek(handle,47,SEEK_SET); //Ïðîïóñê øàïêè (47 ñèìâîëîâ)
if(FileSize(handle)>47){
while(pos<FileSize(handle)){
hCount++;
ArrayResize(hTime, hCount);
temp = FileReadString(handle);
hTime[hCount-1]=StringSubstr(temp,0,4)+"."+StringSubstr(temp,5,2)+"."+StringSubstr(temp,8,2)+",00:00";
ArrayResize(hOpen, hCount);
hOpen[hCount-1]=StrToDouble(FileReadString(handle));
ArrayResize(hHigh, hCount);
hHigh[hCount-1]=StrToDouble(FileReadString(handle));
ArrayResize(hLow, hCount);
hLow[hCount-1]=StrToDouble(FileReadString(handle));
temp = FileReadString(handle); //Çäåñü ïðîïóñêàåì öåíó Settle
ArrayResize(hVolume, hCount);
hVolume[hCount-1]=StrToInteger(FileReadString(handle));
temp = FileReadString(handle); //Çäåñü ïðîïóñêàåì Open Interest
pos=FileTell(handle);
}//End While
}
FileClose(handle);
}
//======== ÇÀÏÈÑÜ =======
handle=FileOpen(OutputFileName,FILE_CSV|FILE_WRITE,',');
temp = DoubleToStr(hOpen[hCount-2], SymbolDigits);
for(pos = hCount-1; pos >= 0; pos--){
if(hOpen[pos]<0.0000001) continue;
FileWrite(handle,
hTime[pos],
DoubleToStr(hOpen[pos], SymbolDigits),
DoubleToStr(hHigh[pos], SymbolDigits),
DoubleToStr(hLow[pos], SymbolDigits),
temp,
DoubleToStr(hVolume[pos], 0)
);
if(pos>1) temp = DoubleToStr(hOpen[pos-2], SymbolDigits);
}
FileClose(handle);
}//start()
//+----------------------------------------------------------------------------+
Comments