EA-Setka-2/bin_to_csv.mq5

170 lines
11 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 14:50:44 +02:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| bin_to_cvs.mq5 |
//| Copyright 2022, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#property script_show_inputs
#define _LBF_UTIL
enum day_of_week_t
{
day_of_week_t_sunday = 0,
day_of_week_t_monday = 1,
day_of_week_t_tuesday = 2,
day_of_week_t_wednesday = 3,
day_of_week_t_thursday = 4,
day_of_week_t_friday = 5,
day_of_week_t_saturday = 6
};
#include "logic\enum\enum.mqh"
#include "framework\enum\enum.mqh"
#include "Libs\CtrlPanel\Common\LBFFunction_V2.mqh"
input string fileName="drawdown.bin";
input bool decimalSeparatorComma=true;
input bool writeSetFile=true;
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
ResetLastError();
//---
int handleFrom=FileOpen(fileName, FILE_READ | FILE_WRITE | FILE_BIN);
if(handleFrom == INVALID_HANDLE)
{
Print("H81:0 ?@8 >B:@KB85 18=0@=>3> D09;0 ?@>A04:8 "+ fileName +" , :>4 ="+IntegerToString(GetLastError()));
return;
}
string fileNameTo=fileName+".csv";
int handleTo=FileOpen(fileNameTo, FILE_READ | FILE_WRITE | FILE_CSV | FILE_UNICODE,"\t");
if(handleTo == INVALID_HANDLE)
{
Print("H81:0 ?@8 A>740=85 CSV D09;0 ?@>A04:8 "+ fileNameTo +" , :>4 ="+IntegerToString(GetLastError()));
return;
}
LBFHeader header;
uint bytesread=0;
bytesread=FileReadStruct(handleFrom,header);
if(bytesread!=sizeof(LBFHeader))
{
PrintFormat("H81:0 GB5=8O 40==KE 87 D09;0 8AB>G=8:0! >4 >H81:8=%d",GetLastError());
//--- 70:@K205< D09;
FileClose(handleFrom);
FileClose(handleTo);
return;
}
string s1=CharArrayToString(header.word);
PrintFormat("0==K5 703>;>2:0 - word: %s, version: %d, bot_ver: %s, bot_mod: %s, leverage: %d, items: %d, set_size: %d",
s1, header.format_ver, CharArrayToString(header.bot_ver), CharArrayToString(header.bot_mod), header.leverage, header.count_item, header.size_of_set_struct);
if(StringCompare(s1,LBF_WORD,false)!=0)
{
PrintFormat("$09; %s =5 A>45@68B B5;5<5B@8N EA-Setka 87 B5AB5@0 AB@0B5389!", fileName);
//--- 70:@K205< D09;
FileClose(handleFrom);
FileClose(handleTo);
return;
}
if(header.format_ver!=LBF_VERSION)
{
PrintFormat("5@A8O %d D09;0 %s =5 <>65B 1KBL >1@01>B0=0 40==>9 CB8;8B>9!", header.format_ver,fileName);
//--- 70:@K205< D09;
FileClose(handleFrom);
FileClose(handleTo);
}
LBFWriteHeaderCVSFile(handleTo);
LBFBalanceItem balanceItem;
int i;
for(i=0; i<header.count_item; i++)
{
bytesread=FileReadStruct(handleFrom,balanceItem);
if(bytesread!=sizeof(LBFBalanceItem))
{
PrintFormat("H81:0 GB5=8O 40==KE, 8=45:A M;5<5=B0 %d. !>740=85 D09;0 %s >AB0=>2;5=>. >4 >H81:8=%d",i,fileNameTo,GetLastError());
//--- 70:@K205< D09;
FileClose(handleFrom);
FileClose(handleTo);
return;
}
LBFWriteItemToCVSFile(handleTo, balanceItem, decimalSeparatorComma);
}
string str;
#ifdef __MQL4__
str=StringConcatenate("!>740= D09; ?@>A04:8 ",TerminalInfoString(TERMINAL_DATA_PATH),"\\Files\\",fileNameTo,", 70?8A0= <0AA82 87 ", IntegerToString(i)," M;5<5=B>2!");
#else
StringConcatenate(str,"!>740= D09; ?@>A04:8 ",TerminalInfoString(TERMINAL_DATA_PATH),"\\Files\\",fileNameTo,", 70?8A0= <0AA82 87 ", IntegerToString(i)," M;5<5=B>2!");
#endif
Print(str);
if(writeSetFile)
{
string fileNameSet=fileName+".set";
int handleSet=FileOpen(fileNameSet, FILE_READ | FILE_WRITE | FILE_TXT | FILE_ANSI);
if(handleSet != INVALID_HANDLE)
{
if(header.size_of_set_struct==sizeof(LBFSetStruct))
{
LBFSetStruct sst;
bytesread=FileReadStruct(handleFrom,sst);
if(bytesread==sizeof(LBFSetStruct))
{
LBFWriteSetToCSVFile(handleSet,header,sst);
}
else
{
PrintFormat("H81:0 GB5=8O A5B0 87 D09;0 8AB>G=8:0! >4 >H81:8=%d",GetLastError());
}
}
else
{
PrintFormat("!B@C:BC@0 A5B0 =5 <>65B 1KBL @07>1@0=0 MB>9 25@A859 CB8;8BK. >4 >H81:8=%d",fileNameSet);
}
#ifdef __MQL4__
str=StringConcatenate("!>740= D09; A5B0 ",TerminalInfoString(TERMINAL_DATA_PATH),"\\Files\\",fileNameSet);
#else
StringConcatenate(str,"!>740= D09; A5B0 ",TerminalInfoString(TERMINAL_DATA_PATH),"\\Files\\",fileNameSet);
#endif
Print(str);
FileClose(handleSet);
}
else
{
Print("H81:0 ?@8 A>740=85 SET D09;0 ?@>A04:8 "+ fileNameSet +" , :>4 ="+IntegerToString(GetLastError()));
}
}
FileClose(handleFrom);
FileClose(handleTo);
}
//+------------------------------------------------------------------+