209 라인
6.3 KiB
MQL5
209 라인
6.3 KiB
MQL5
//+------------------------------------------------------------------+
| |||
//| Saver.mqh |
| |||
//| Copyright 2025, Niquel Mendoza. |
| |||
//| https://www.mql5.com/es/users/nique_372 |
| |||
//+------------------------------------------------------------------+
| |||
#property copyright "Copyright 2025, Niquel Mendoza."
| |||
#property link "https://www.mql5.com/es/users/nique_372"
| |||
#property strict
| |||
| |||
#ifndef AIDATATASKRUNNER_BACKEND_BASES_SAVER_MQH
| |||
#define AIDATATASKRUNNER_BACKEND_BASES_SAVER_MQH
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| |
| |||
//+------------------------------------------------------------------+
| |||
#include "Defines.mqh"
| |||
| |||
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| |
| |||
//+------------------------------------------------------------------+
| |||
class CTaskSaver : public CLoggerBase
| |||
{
| |||
public:
| |||
CTaskSaver(void) {}
| |||
~CTaskSaver(void) {}
| |||
| |||
//---
| |||
bool LoadC(const string& file_name, int fc, string& msg, string& progress, string& arr_fmove[], string& mainfolder, string& exp_path);
| |||
bool SaveC(const string& file_name, int fc, string& msg, const string& progress,
| |||
const string& arr_fmove[], const string& mainfolder, const string& exp_path);
| |||
| |||
//---
| |||
bool Load(const string& file_name, TaskTester& arr[], int& size, int file_common, string& msg);
| |||
bool Save(const string& file_name, TaskTester& arr[], int size, int file_common, bool filter, string& msg);
| |||
};
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| |
| |||
//+------------------------------------------------------------------+
| |||
bool CTaskSaver::LoadC(const string &file_name, int fc, string &msg, string &progress, string &arr_fmove[], string &mainfolder, string &exp_path)
| |||
{
| |||
//---
| |||
::ResetLastError();
| |||
const int fh = FileOpen(file_name, FILE_READ | FILE_TXT | fc);
| |||
if(fh == INVALID_HANDLE)
| |||
{
| |||
msg = (StringFormat("Fallo al abrir el archivo = %s, ultimo error = %d", file_name, ::GetLastError()));
| |||
return false;
| |||
}
| |||
| |||
//---
| |||
progress = FileReadString(fh);
| |||
mainfolder = FileReadString(fh);
| |||
exp_path = FileReadString(fh);
| |||
| |||
//---
| |||
const int t = StringSplit(FileReadString(fh), '|', g_str_arr_dyn_arr);
| |||
if(t == -1)
| |||
{
| |||
msg = "Fallo al hacer split move files";
| |||
FileClose(fh);
| |||
return false;
| |||
}
| |||
else
| |||
{
| |||
ArrayCopy(arr_fmove, g_str_arr_dyn_arr);
| |||
}
| |||
| |||
//---
| |||
FileClose(fh);
| |||
| |||
//---
| |||
return true;
| |||
}
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| |
| |||
//+------------------------------------------------------------------+
| |||
bool CTaskSaver::SaveC(const string &file_name, int fc, string &msg, const string &progress, const string &arr_fmove[], const string &mainfolder, const string &exp_path)
| |||
{
| |||
//---
| |||
::ResetLastError();
| |||
const int fh = FileOpen(file_name, FILE_WRITE | FILE_TXT | fc);
| |||
if(fh == INVALID_HANDLE)
| |||
{
| |||
msg = (StringFormat("Fallo al abrir el archivo = %s, ultimo error = %d", file_name, ::GetLastError()));
| |||
return false;
| |||
}
| |||
| |||
//---
| |||
FileWrite(fh, progress);
| |||
FileWrite(fh, mainfolder);
| |||
FileWrite(fh, exp_path);
| |||
FileWrite(fh, ArrayStrToString(arr_fmove, "|"));
| |||
| |||
//---
| |||
FileClose(fh);
| |||
| |||
//---
| |||
return true;
| |||
| |||
}
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| |
| |||
//+------------------------------------------------------------------+
| |||
bool CTaskSaver::Save(const string &file_name, TaskTester &arr[], int size, int file_common, bool filter, string& msg)
| |||
{
| |||
//---
| |||
::ResetLastError();
| |||
const int fh = FileOpen(file_name, FILE_WRITE | FILE_CSV | file_common);
| |||
if(fh == INVALID_HANDLE)
| |||
{
| |||
msg = (StringFormat("Fallo al abrir el archivo = %s, ultimo error = %d", file_name, ::GetLastError()));
| |||
return false;
| |||
}
| |||
//---
| |||
FileWrite(fh, "Timeframe,Symbol,SetFile,SymbolFolderName,Label,LabelId,StartDate,EndDate");
| |||
| |||
//---
| |||
for(int i = 0; i < size; i++)
| |||
{
| |||
if(!filter || (arr[i].state == AIEXECUTOR_TASK_STATE_IN_PROCESS
| |||
|| arr[i].state == AIEXECUTOR_TASK_STATE_IN_QUEQE
| |||
|| arr[i].state == AIEXECUTOR_TASK_STATE_PENDIENTE))
| |||
FileWrite(fh, arr[i].ToStringFile());
| |||
}
| |||
| |||
//---
| |||
FileClose(fh);
| |||
return true;
| |||
}
| |||
| |||
//+------------------------------------------------------------------+
| |||
bool CTaskSaver::Load(const string &file_name, TaskTester& arr[], int& size, int file_common, string& msg)
| |||
{
| |||
//---
| |||
if(FileIsExist(file_name))
| |||
{
| |||
//---
| |||
::ResetLastError();
| |||
const int fh = FileOpen(file_name, FILE_READ | FILE_CSV | file_common);
| |||
if(fh == INVALID_HANDLE)
| |||
{
| |||
msg = (StringFormat("Fallo al abrir el archivo = %s, ultimo error = %d", file_name, ::GetLastError()));
| |||
return false;
| |||
}
| |||
| |||
//---
| |||
FileReadString(fh); // Cabezera
| |||
| |||
//---
| |||
size = ArrayResize(arr, 0);
| |||
| |||
//---
| |||
string arr_str[8];
| |||
while(FileIsEnding(fh))
| |||
{
| |||
if(StringSplit(FileReadString(fh), ',', arr_str) != 8)
| |||
{
| |||
LogWarning("Linea invalida omitida", FUNCION_ACTUAL);
| |||
continue;
| |||
}
| |||
| |||
//---
| |||
static TaskTester task;
| |||
task.Assing(arr_str);
| |||
| |||
//---
| |||
if(task.state == AIEXECUTOR_TASK_STATE_FINISHED || task.state == AIEXECUTOR_TASK_STATE_FAILED)
| |||
continue;
| |||
| |||
//---
| |||
arr[ArrayResize(arr, (++size)) - 1] = task;
| |||
}
| |||
| |||
| |||
//---
| |||
FileClose(fh);
| |||
}
| |||
else
| |||
{
| |||
LogWarning("No se enocnrro un archivo del cual cargar", FUNCION_ACTUAL);
| |||
}
| |||
| |||
| |||
//---
| |||
return true;
| |||
}
| |||
| |||
| |||
//+------------------------------------------------------------------+
| |||
/*
| |||
ExpertPath=ICTRaptor.ex5
| |||
MainFolder=ICTKiller\\
| |||
TemporalFIleName=none
| |||
MoveFilesName=pred.csv,sl.csv,tp.csv,scaler_tp.csv,scaler_sl.csv,scaler_pred.csv
| |||
| |||
*/
| |||
| |||
/*
| |||
Timeframe,Symbol,SetFile,SymbolFolderName,Label,LabelId,StartDate,EndDate
| |||
1,XAUUSD,ICTKiller\\XAUUSD\\M1\\Best\\data.set,XAUUSD,Best,0,2025.01.01 10:10:10,2026.01.01
| |||
*/
| |||
| |||
//+------------------------------------------------------------------+
| |||
#endif // AIDATATASKRUNNER_BACKEND_BASES_SAVER_MQH
|