forked from nique_372/AiDataGenByLeo
392 lines
No EOL
24 KiB
MQL5
392 lines
No EOL
24 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Complex.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 AIDATAGENBYLEO_GENERIC_DATA_BASE_COMPLEX_MQH
|
|
#define AIDATAGENBYLEO_GENERIC_DATA_BASE_COMPLEX_MQH
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
#include "Saver.mqh"
|
|
#include "Base.mqh"
|
|
|
|
//---
|
|
#define AILEO_COMPLEX_HEADER_SEP ","
|
|
#define AILEO_COMPLEX_GENERIC_COL_NAME "Col_"
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
// Solo para repartir el estado global
|
|
class CAiLeoMulyiFeatureGen : public CLoggerBase
|
|
{
|
|
private:
|
|
//---
|
|
string m_name;
|
|
string m_header;
|
|
ENUM_AIDATA_GEN_TYPE m_type;
|
|
bool m_init;
|
|
|
|
//---
|
|
ulong m_cols;
|
|
ulong m_rows;
|
|
|
|
//---
|
|
string m_symbol;
|
|
double m_bid;
|
|
double m_ask;
|
|
|
|
|
|
//---
|
|
vector m_v;
|
|
|
|
//---
|
|
int m_idx_m1[];
|
|
int m_idx_m1_size;
|
|
|
|
//---
|
|
CAiDataLeoFeature* m_features[];
|
|
int m_features_size;
|
|
|
|
//---
|
|
CAiLeoMulyiFeatureGenSaver* m_saver;
|
|
|
|
//---
|
|
void SetHeader();
|
|
|
|
public:
|
|
CAiLeoMulyiFeatureGen();
|
|
~CAiLeoMulyiFeatureGen();
|
|
|
|
//---
|
|
void Clean();
|
|
|
|
//--- Iniciar
|
|
// Inicializacion normal
|
|
bool Init(const string& name, const string& src);
|
|
|
|
//template <typename TFeaturesFactory>
|
|
// Inicializacion por file
|
|
bool InitByFile(const string& file_name, bool comon);
|
|
|
|
//--- Guardar
|
|
__forceinline bool Save(const string& file_name, bool comon);
|
|
|
|
//--- Obtener datos
|
|
void ObtenerDataEnMatrix(matrix& mtx, const datetime curr_time); // Obtiene un matrix
|
|
void ObtenerDataEnVector(vector& vct, const datetime curr_time); // Obtiene un vector
|
|
void ObtenerVectorAsMatrix(matrix& mtx, const datetime curr_time); // Obtiene un vector solo que como matrix
|
|
|
|
//--- Summary
|
|
void Summary() const;
|
|
|
|
//---
|
|
// CUIDADO puede dar errores..
|
|
// El headerva separado por , siempre debera de tener el mismo tamaño que COLS.. esa es la idea
|
|
// En caso no lo tenga la clase se abstiene a hacer comprobaciones... asi que
|
|
// Las modificaiones que se hagan al header.. ud debera de tener cuidado
|
|
__forceinline string Header() const { return m_header; }
|
|
void Header(const string& v) { m_header = v; }
|
|
|
|
//---
|
|
void OnNewBarM1(const datetime curr_time);
|
|
|
|
//--- Puntero de saver
|
|
const CAiLeoMulyiFeatureGenSaver* const GetSaverPtr() { return m_saver; }
|
|
|
|
//---
|
|
static void GetDataCts(vector& res, const int &indexs[], const int indexs_size, const vector& v);
|
|
};
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
CAiLeoMulyiFeatureGen::CAiLeoMulyiFeatureGen()
|
|
: m_init(false), m_symbol(_Symbol), m_header(NULL)
|
|
{
|
|
m_saver = new CAiLeoMulyiFeatureGenSaver();
|
|
m_features_size = ArrayResize(m_features, 0);
|
|
m_idx_m1_size = ArrayResize(m_idx_m1, 0);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
CAiLeoMulyiFeatureGen::~CAiLeoMulyiFeatureGen(void)
|
|
{
|
|
Clean();
|
|
if(CheckPointer(m_saver) == POINTER_DYNAMIC)
|
|
delete m_saver;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
void CAiLeoMulyiFeatureGen::Clean(void)
|
|
{
|
|
//---
|
|
m_cols = 0;
|
|
m_rows = 0;
|
|
m_type = WRONG_VALUE;
|
|
m_name = NULL;
|
|
m_init = false;
|
|
m_saver.Clean();
|
|
m_header = NULL;
|
|
|
|
//--- Eliminamos los puntos
|
|
for(int i = 0; i < m_features_size; i++)
|
|
{
|
|
if(CheckPointer(m_features[i]) == POINTER_DYNAMIC)
|
|
delete m_features[i];
|
|
}
|
|
m_features_size = ArrayResize(m_features, 0);
|
|
|
|
//---
|
|
m_idx_m1_size = ArrayResize(m_idx_m1, 0);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Funciones de inicilizacion |
|
|
//| 1. Funcion de incilizacion normal por src |
|
|
//| 2. Funcion de iniclziacion por file AIDATABYLEO_FILE_EXT |
|
|
//+------------------------------------------------------------------+
|
|
bool CAiLeoMulyiFeatureGen::Init(const string& name, const string& src)
|
|
{
|
|
//--- Verificamos si esta iniciado
|
|
if(m_init)
|
|
{
|
|
LogWarning("Se esta limpiadno la clase, dado que ya esta iniciada", FUNCION_ACTUAL);
|
|
Clean();
|
|
}
|
|
|
|
|
|
//--- Parseamos
|
|
if(!g_ai_data_features_parser.Parse(src, m_features, m_features_size, m_type, m_cols, m_rows))
|
|
{
|
|
LogError(StringFormat("Fallo al parsear:\n%s", src), FUNCION_ACTUAL);
|
|
return false;
|
|
}
|
|
|
|
//--- Seteamos el nombre (en el parse ya se setea el resto)
|
|
m_name = name;
|
|
m_init = true; // Se inicio correctamente
|
|
|
|
//---
|
|
for(int i = 0; i < m_features_size; i++)
|
|
{
|
|
if(m_features[i].UseOnNewBarM1())
|
|
{
|
|
m_idx_m1[ArrayResize(m_idx_m1, ++m_idx_m1_size) - 1] = i;
|
|
}
|
|
}
|
|
|
|
//---
|
|
SetHeader();
|
|
|
|
//---
|
|
return true;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
bool CAiLeoMulyiFeatureGen::InitByFile(const string &file_name, bool comon)
|
|
{
|
|
//--- Verificamos si esta iniciado
|
|
if(m_init)
|
|
{
|
|
LogWarning("Se esta limpiadno la clase, dado que ya esta iniciada", FUNCION_ACTUAL);
|
|
Clean();
|
|
}
|
|
|
|
//---
|
|
if(!m_saver.Load(file_name, comon))
|
|
return false;
|
|
|
|
//--- Parseamos
|
|
string src = m_saver.Src();
|
|
if(!g_ai_data_features_parser.Parse(src, m_features, m_features_size, m_type, m_cols, m_rows))
|
|
{
|
|
LogError(StringFormat("Fallo al parsear:\n%s", src), FUNCION_ACTUAL);
|
|
return false;
|
|
}
|
|
|
|
//--- Seteamos el nombre (en el parse ya se setea el resto)
|
|
m_name = m_saver.Name();
|
|
m_init = true; // Se inicio correctamente
|
|
|
|
//---
|
|
for(int i = 0; i < m_features_size; i++)
|
|
{
|
|
if(m_features[i].UseOnNewBarM1())
|
|
{
|
|
m_idx_m1[ArrayResize(m_idx_m1, ++m_idx_m1_size) - 1] = i;
|
|
}
|
|
}
|
|
|
|
//---
|
|
SetHeader();
|
|
|
|
//---
|
|
return true;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
__forceinline bool CAiLeoMulyiFeatureGen::Save(const string &file_name, bool comon)
|
|
{
|
|
return m_saver.Save(file_name, comon);
|
|
}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
void CAiLeoMulyiFeatureGen::OnNewBarM1(const datetime curr_time)
|
|
{
|
|
//---
|
|
m_bid = SymbolInfoDouble(m_symbol, SYMBOL_BID);
|
|
m_ask = SymbolInfoDouble(m_symbol, SYMBOL_ASK);
|
|
|
|
//---
|
|
for(int i = 0; i < m_idx_m1_size; i++)
|
|
{
|
|
m_features[m_idx_m1[i]].OnNewBarM1(curr_time, m_bid, m_ask);
|
|
}
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Funciones para generar data |
|
|
//| Nota: |
|
|
//| - Recomiendo saber de ante mano cual llamar |
|
|
//+------------------------------------------------------------------+
|
|
void CAiLeoMulyiFeatureGen::ObtenerDataEnMatrix(matrix &mtx, const datetime curr_time)
|
|
{
|
|
//---
|
|
m_bid = SymbolInfoDouble(m_symbol, SYMBOL_BID);
|
|
m_ask = SymbolInfoDouble(m_symbol, SYMBOL_ASK);
|
|
|
|
//---
|
|
mtx.Resize(m_rows, m_cols);
|
|
ulong start_r = 0;
|
|
ulong end_r = 0;
|
|
ulong col = 0;
|
|
ulong k = 0;
|
|
|
|
//---
|
|
for(int i = 0; i < m_features_size; i++)
|
|
{
|
|
col = m_features[i].MtxStartCol();
|
|
start_r = m_features[i].MtxStartRow();
|
|
end_r = m_features[i].MtxEndRow();
|
|
m_v = m_features[i].GetValue(curr_time, m_bid, m_ask);
|
|
k = 0;
|
|
|
|
for(ulong r = start_r; r <= end_r; r++)
|
|
{
|
|
mtx[r][col] = m_v[k++];
|
|
}
|
|
}
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
void CAiLeoMulyiFeatureGen::ObtenerDataEnVector(vector &vct, const datetime curr_time)
|
|
{
|
|
//---
|
|
m_bid = SymbolInfoDouble(m_symbol, SYMBOL_BID);
|
|
m_ask = SymbolInfoDouble(m_symbol, SYMBOL_ASK);
|
|
|
|
//---
|
|
vct.Resize(m_cols);
|
|
for(ulong i = 0; i < m_cols; i++)
|
|
{
|
|
vct[i] = m_features[i].GetValue(curr_time, m_bid, m_ask)[0]; // Valor 0
|
|
// Print(vct[i]);
|
|
}
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
void CAiLeoMulyiFeatureGen::ObtenerVectorAsMatrix(matrix &mtx, const datetime curr_time)
|
|
{
|
|
//---
|
|
m_bid = SymbolInfoDouble(m_symbol, SYMBOL_BID);
|
|
m_ask = SymbolInfoDouble(m_symbol, SYMBOL_ASK);
|
|
|
|
//---
|
|
mtx.Resize(m_rows, m_cols); // ROWS = 1
|
|
for(ulong i = 0; i < m_cols; i++)
|
|
{
|
|
mtx[i][0] = m_features[i].GetValue(curr_time, m_bid, m_ask)[0]; // Valor 0
|
|
}
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
void CAiLeoMulyiFeatureGen::Summary(void) const
|
|
{
|
|
PrintFormat("---| Summary of = %s", m_name);
|
|
PrintFormat(" Type = %s", EnumToString(m_type));
|
|
PrintFormat(" Cols = %I64u", m_cols);
|
|
PrintFormat(" Rows = %I64u", m_rows);
|
|
Print(" --------- ");
|
|
for(int i = 0; i < m_features_size; i++)
|
|
{
|
|
Print(m_features[i].Summary() + "\n");
|
|
}
|
|
Print("--- Fin");
|
|
}
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
void CAiLeoMulyiFeatureGen::SetHeader(void)
|
|
{
|
|
//---
|
|
m_header = "";
|
|
|
|
//---
|
|
if(m_type == AIDATALEO_GEN_VECTOR)
|
|
{
|
|
//--- Vector usa nombres reales
|
|
for(ulong i = 0; i < m_cols; i++)
|
|
{
|
|
m_header += m_features[i].FullName();
|
|
if(i < m_cols - 1)
|
|
m_header += AILEO_COMPLEX_HEADER_SEP;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//--- Matrix usa nombres genericos
|
|
for(ulong i = 0; i < m_cols; i++)
|
|
{
|
|
m_header += AILEO_COMPLEX_GENERIC_COL_NAME + string(i);
|
|
if(i < m_cols - 1)
|
|
m_header += AILEO_COMPLEX_HEADER_SEP;
|
|
}
|
|
}
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
static void CAiLeoMulyiFeatureGen::GetDataCts(vector& res, const int &indexs[], const int indexs_size, const vector& v)
|
|
{
|
|
//---
|
|
res.Resize(indexs_size);
|
|
|
|
//---
|
|
for(int i = 0; i < indexs_size; i++)
|
|
{
|
|
res[i] = v[indexs[i]];
|
|
}
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
#endif // AIDATAGENBYLEO_GENERIC_DATA_BASE_COMPLEX_MQH
|
|
//+------------------------------------------------------------------+
|
|
|