169 lines
11 KiB
MQL5
169 lines
11 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| 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("Ошибка при открытие бинарного файла просадки "+ fileName +" , код ="+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("Ошибка при создание CSV файла просадки "+ fileNameTo +" , код ="+IntegerToString(GetLastError()));
|
|
return;
|
|
}
|
|
|
|
LBFHeader header;
|
|
uint bytesread=0;
|
|
bytesread=FileReadStruct(handleFrom,header);
|
|
|
|
if(bytesread!=sizeof(LBFHeader))
|
|
{
|
|
PrintFormat("Ошибка чтения данных из файла источника! Код ошибки=%d",GetLastError());
|
|
//--- закрываем файл
|
|
FileClose(handleFrom);
|
|
FileClose(handleTo);
|
|
return;
|
|
}
|
|
string s1=CharArrayToString(header.word);
|
|
PrintFormat("Данные заголовка - 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("Файл %s не содержит телеметрию EA-Setka из тестера стратегий!", fileName);
|
|
//--- закрываем файл
|
|
FileClose(handleFrom);
|
|
FileClose(handleTo);
|
|
return;
|
|
}
|
|
|
|
|
|
if(header.format_ver!=LBF_VERSION)
|
|
{
|
|
PrintFormat("Версия %d файла %s не может быть обработана данной утилитой!", header.format_ver,fileName);
|
|
//--- закрываем файл
|
|
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("Ошибка чтения данных, индекс элемента %d. Создание файла %s остановлено. Код ошибки=%d",i,fileNameTo,GetLastError());
|
|
//--- закрываем файл
|
|
FileClose(handleFrom);
|
|
FileClose(handleTo);
|
|
return;
|
|
}
|
|
LBFWriteItemToCVSFile(handleTo, balanceItem, decimalSeparatorComma);
|
|
}
|
|
|
|
string str;
|
|
#ifdef __MQL4__
|
|
str=StringConcatenate("Создан файл просадки ",TerminalInfoString(TERMINAL_DATA_PATH),"\\Files\\",fileNameTo,", записан массив из ", IntegerToString(i)," элементов!");
|
|
#else
|
|
StringConcatenate(str,"Создан файл просадки ",TerminalInfoString(TERMINAL_DATA_PATH),"\\Files\\",fileNameTo,", записан массив из ", IntegerToString(i)," элементов!");
|
|
#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("Ошибка чтения сета из файла источника! Код ошибки=%d",GetLastError());
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
PrintFormat("Структура сета не может быть разобрана этой версией утилиты. Код ошибки=%d",fileNameSet);
|
|
}
|
|
|
|
#ifdef __MQL4__
|
|
str=StringConcatenate("Создан файл сета ",TerminalInfoString(TERMINAL_DATA_PATH),"\\Files\\",fileNameSet);
|
|
#else
|
|
StringConcatenate(str,"Создан файл сета ",TerminalInfoString(TERMINAL_DATA_PATH),"\\Files\\",fileNameSet);
|
|
#endif
|
|
Print(str);
|
|
|
|
FileClose(handleSet);
|
|
}
|
|
else
|
|
{
|
|
Print("Ошибка при создание SET файла просадки "+ fileNameSet +" , код ="+IntegerToString(GetLastError()));
|
|
}
|
|
}
|
|
|
|
|
|
FileClose(handleFrom);
|
|
FileClose(handleTo);
|
|
|
|
|
|
}
|
|
//+------------------------------------------------------------------+
|