forked from nique_372/MQLArticles
Los .mqh estaban corruptos en el working tree porque core.autocrlf normalizaba bytes de un archivo UTF-16LE como si fuera texto de 1 byte por caracter, desalineando el contenido tras la primera linea. Se reconstruyeron desde el blob de git (HEAD), no desde el working tree, y se verifico igualdad byte a byte contra la conversion limpia antes de commitear. Los .set estaban marcados binary en .gitattributes y no sufrian este problema; solo se les cambio el encoding.
428 lines
13 KiB
MQL5
428 lines
13 KiB
MQL5
//+------------------------------------------------------------------+
| |
//| Events.mqh |
| |
//| Niquel y Leo, Copyright 2025. |
| |
//| https://www.mql5.com |
| |
//+------------------------------------------------------------------+
| |
#property copyright "Niquel y Leo, Copyright 2025"
| |
#property link "https://www.mql5.com"
| |
#property strict
| |
| |
| |
#ifndef MQLARTICLES_UTILS_FA_EVENTS_MQH
| |
#define MQLARTICLES_UTILS_FA_EVENTS_MQH
| |
| |
//+------------------------------------------------------------------+
| |
//| Include |
| |
//+------------------------------------------------------------------+
| |
#include "Managers.mqh"
| |
| |
//+------------------------------------------------------------------+
| |
//| Clase base para los eventos basicos |
| |
//+------------------------------------------------------------------+
| |
class CAllClassEventsBasic : public CSpecializedManager
| |
{
| |
protected:
| |
//--- Impidimos la instanciacion solo ptr.. pero se debe de asignar..
| |
CAllClassEventsBasic() {}
| |
public:
| |
~CAllClassEventsBasic() {}
| |
| |
//--- Eventos basicos
| |
// Nota: Estos eventos son los basicos
| |
virtual void OnNewDay(const datetime curr_time) {}
| |
virtual void OnNewWeek(const datetime curr_time) {}
| |
virtual void OnNewMonth(const datetime curr_time) {}
| |
};
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| Clase base para los eventos |
| |
//+------------------------------------------------------------------+
| |
#define BASICEVENT_REG_FLAG_ON_NEW_DAY (1)
| |
#define BASICEVENT_REG_FLAG_ON_NEW_WEEK (2)
| |
#define BASICEVENT_REG_FLAG_ON_NEW_MON (4)
| |
| |
//---
| |
#define BASICEVENT_REG_ALL_FLAG (BASICEVENT_REG_FLAG_ON_NEW_DAY|BASICEVENT_REG_FLAG_ON_NEW_WEEK|BASICEVENT_REG_FLAG_ON_NEW_MON)
| |
| |
#define BASICEVENT_LFLAG_FREE (1)
| |
#define BASICEVENT_LFLAG_INIT (2)
| |
| |
| |
//---
| |
class CBasicEvents
| |
{
| |
private:
| |
| |
static uint8_t m_flags;
| |
static CAllClassEventsBasic* m_on_new_day[];
| |
static int m_on_new_day_size;
| |
| |
static CAllClassEventsBasic* m_on_new_week[];
| |
static int m_on_new_week_size;
| |
| |
static CAllClassEventsBasic* m_on_new_mon[];
| |
static int m_on_new_mon_size;
| |
| |
//---
| |
static void RemoveFromArrayFast(CAllClassEventsBasic* &array[], int &size, CAllClassEventsBasic* &ptr);
| |
| |
public:
| |
CBasicEvents(void) {}
| |
~CBasicEvents(void) {}
| |
| |
//--- Registrar
| |
static void Register(CAllClassEventsBasic* ptr, const uint8_t flags);
| |
static void RegisterEvent(CAllClassEventsBasic* ptr, const uint8_t event);
| |
| |
static void Unregister(CAllClassEventsBasic* ptr, const uint8_t flags);
| |
static void UnregisterEvent(CAllClassEventsBasic* ptr, const uint8_t event);
| |
| |
| |
//--- Eventos
| |
static void OnNewDay(const datetime curr_time);
| |
static void OnNewWeek(const datetime curr_time);
| |
static void OnNewMonth(const datetime curr_time);
| |
| |
//---
| |
static void Deinit(const int reason);
| |
static void Init();
| |
| |
//---
| |
static __forceinline bool IsActive() { return m_flags == BASICEVENT_LFLAG_INIT; }
| |
};
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
static void CBasicEvents::Init()
| |
{
| |
//---
| |
if((m_flags & BASICEVENT_LFLAG_INIT) != 0)
| |
return;
| |
| |
//---
| |
m_on_new_day_size = ArrayResize(m_on_new_day, 0);
| |
m_on_new_week_size = ArrayResize(m_on_new_week, 0);
| |
m_on_new_mon_size = ArrayResize(m_on_new_mon, 0);
| |
| |
//---
| |
m_flags |= BASICEVENT_LFLAG_INIT;
| |
}
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
static void CBasicEvents::Deinit(const int reason)
| |
{
| |
if((m_flags & BASICEVENT_LFLAG_INIT) == BASICEVENT_LFLAG_INIT)
| |
{
| |
m_on_new_day_size = ArrayResize(m_on_new_day, 0);
| |
m_on_new_week_size = ArrayResize(m_on_new_week, 0);
| |
m_on_new_mon_size = ArrayResize(m_on_new_mon, 0);
| |
| |
//---
| |
m_flags |= BASICEVENT_LFLAG_FREE;
| |
}
| |
}
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
static void CBasicEvents::RemoveFromArrayFast(CAllClassEventsBasic* &array[], int &size, CAllClassEventsBasic* &ptr)
| |
{
| |
for(int i = 0; i < size; i++)
| |
{
| |
if(array[i] == ptr)
| |
{
| |
array[i] = array[size - 1];
| |
ArrayResize(array, --size);
| |
return;
| |
}
| |
}
| |
}
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
static void CBasicEvents::Unregister(CAllClassEventsBasic* ptr, const uint8_t flags)
| |
{
| |
if(!CheckPointer(ptr))
| |
{
| |
FastLog(FUNCION_ACTUAL, WARNING_TEXT, "Invalid pointer for unregister");
| |
return;
| |
}
| |
| |
//--- OnNewDay
| |
if((flags & BASICEVENT_REG_FLAG_ON_NEW_DAY) != 0)
| |
RemoveFromArrayFast(m_on_new_day, m_on_new_day_size, ptr);
| |
| |
//--- OnNewWeek
| |
if((flags & BASICEVENT_REG_FLAG_ON_NEW_WEEK) != 0)
| |
RemoveFromArrayFast(m_on_new_week, m_on_new_week_size, ptr);
| |
| |
//--- OnNewMonth
| |
if((flags & BASICEVENT_REG_FLAG_ON_NEW_MON) != 0)
| |
RemoveFromArrayFast(m_on_new_mon, m_on_new_mon_size, ptr);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
static void CBasicEvents::UnregisterEvent(CAllClassEventsBasic *ptr, const uchar event)
| |
{
| |
if(!CheckPointer(ptr))
| |
{
| |
FastLog(FUNCION_ACTUAL, WARNING_TEXT, "Invalid pointer for unregister");
| |
return;
| |
}
| |
| |
//--- OnNewDay
| |
if(event == BASICEVENT_REG_FLAG_ON_NEW_DAY)
| |
RemoveFromArrayFast(m_on_new_day, m_on_new_day_size, ptr);
| |
| |
//--- OnNewWeek
| |
else
| |
if(event == BASICEVENT_REG_FLAG_ON_NEW_WEEK)
| |
RemoveFromArrayFast(m_on_new_week, m_on_new_week_size, ptr);
| |
//--- OnNewMonth
| |
else
| |
if(event == BASICEVENT_REG_FLAG_ON_NEW_MON)
| |
RemoveFromArrayFast(m_on_new_mon, m_on_new_mon_size, ptr);
| |
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
static void CBasicEvents::RegisterEvent(CAllClassEventsBasic *ptr, const uchar event)
| |
{
| |
//---
| |
if(!CheckPointer(ptr))
| |
{
| |
FastLog(FUNCION_ACTUAL, FATAL_ERROR_TEXT, "No se puede registrar puntos invalidos");
| |
Remover();
| |
return;
| |
}
| |
| |
//---
| |
if(event == BASICEVENT_REG_FLAG_ON_NEW_DAY)
| |
{
| |
m_on_new_day[ArrayResize(m_on_new_day, (++m_on_new_day_size)) - 1 ] = ptr;
| |
}
| |
//---
| |
else
| |
if(event == BASICEVENT_REG_FLAG_ON_NEW_WEEK)
| |
{
| |
m_on_new_week[ArrayResize(m_on_new_week, (++m_on_new_week_size)) - 1 ] = ptr;
| |
}
| |
//---
| |
else
| |
if(event == BASICEVENT_REG_FLAG_ON_NEW_MON)
| |
{
| |
m_on_new_mon[ArrayResize(m_on_new_mon, (++m_on_new_mon_size)) - 1 ] = ptr;
| |
}
| |
}
| |
| |
| |
//+------------------------------------------------------------------+
| |
static void CBasicEvents::Register(CAllClassEventsBasic *ptr, const uint8_t flags)
| |
{
| |
//---
| |
if(!CheckPointer(ptr))
| |
{
| |
FastLog(FUNCION_ACTUAL, FATAL_ERROR_TEXT, "No se puede registrar puntos invalidos");
| |
Remover();
| |
return;
| |
}
| |
| |
//---
| |
if((flags & BASICEVENT_REG_FLAG_ON_NEW_DAY) != 0)
| |
{
| |
m_on_new_day[ArrayResize(m_on_new_day, (++m_on_new_day_size)) - 1 ] = ptr;
| |
}
| |
| |
//---
| |
if((flags & BASICEVENT_REG_FLAG_ON_NEW_WEEK) != 0)
| |
{
| |
m_on_new_week[ArrayResize(m_on_new_week, (++m_on_new_week_size)) - 1 ] = ptr;
| |
}
| |
| |
//---
| |
if((flags & BASICEVENT_REG_FLAG_ON_NEW_MON) != 0)
| |
{
| |
m_on_new_mon[ArrayResize(m_on_new_mon, (++m_on_new_mon_size)) - 1 ] = ptr;
| |
}
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
static void CBasicEvents::OnNewDay(const datetime curr_time)
| |
{
| |
for(int i = 0; i < m_on_new_day_size; i++)
| |
{
| |
m_on_new_day[i].OnNewDay(curr_time);
| |
}
| |
}
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
static void CBasicEvents::OnNewWeek(const datetime curr_time)
| |
{
| |
for(int i = 0; i < m_on_new_week_size; i++)
| |
{
| |
m_on_new_week[i].OnNewWeek(curr_time);
| |
}
| |
}
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
static void CBasicEvents::OnNewMonth(const datetime curr_time)
| |
{
| |
for(int i = 0; i < m_on_new_mon_size; i++)
| |
{
| |
m_on_new_mon[i].OnNewMonth(curr_time);
| |
}
| |
}
| |
| |
| |
//+------------------------------------------------------------------+
| |
CAllClassEventsBasic* CBasicEvents::m_on_new_day[] = {};
| |
int CBasicEvents::m_on_new_day_size = 0;
| |
//---
| |
CAllClassEventsBasic* CBasicEvents::m_on_new_week[] = {};
| |
int CBasicEvents::m_on_new_week_size = 0;
| |
//---
| |
CAllClassEventsBasic*CBasicEvents:: m_on_new_mon[] = {};
| |
int CBasicEvents::m_on_new_mon_size = 0;
| |
//---
| |
uint8_t CBasicEvents::m_flags = 0;
| |
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
/* ---------- Experts
| |
//+------------------------------------------------------------------+
| |
//| Expert initialization function |
| |
//+------------------------------------------------------------------+
| |
int OnInit()
| |
{
| |
//---
| |
| |
//---
| |
return(INIT_SUCCEEDED);
| |
}
| |
//+------------------------------------------------------------------+
| |
//| Expert deinitialization function |
| |
//+------------------------------------------------------------------+
| |
void OnDeinit(const int reason)
| |
{
| |
//---
| |
| |
}
| |
//+------------------------------------------------------------------+
| |
//| Expert tick function |
| |
//+------------------------------------------------------------------+
| |
void OnTick()
| |
{
| |
//---
| |
| |
}
| |
//+------------------------------------------------------------------+
| |
//| Timer function |
| |
//+------------------------------------------------------------------+
| |
void OnTimer()
| |
{
| |
//---
| |
| |
}
| |
//+------------------------------------------------------------------+
| |
//| Trade function |
| |
//+------------------------------------------------------------------+
| |
void OnTrade()
| |
{
| |
//---
| |
| |
}
| |
//+------------------------------------------------------------------+
| |
//| TradeTransaction function |
| |
//+------------------------------------------------------------------+
| |
void OnTradeTransaction(const MqlTradeTransaction& trans,
| |
const MqlTradeRequest& request,
| |
const MqlTradeResult& result)
| |
{
| |
//---
| |
| |
}
| |
//+------------------------------------------------------------------+
| |
//| Tester function |
| |
//+------------------------------------------------------------------+
| |
double OnTester()
| |
{
| |
//---
| |
double ret=0.0;
| |
//---
| |
| |
//---
| |
return(ret);
| |
}
| |
//+------------------------------------------------------------------+
| |
//| TesterInit function |
| |
//+------------------------------------------------------------------+
| |
void OnTesterInit()
| |
{
| |
//---
| |
| |
}
| |
//+------------------------------------------------------------------+
| |
//| TesterPass function |
| |
//+------------------------------------------------------------------+
| |
void OnTesterPass()
| |
{
| |
//---
| |
| |
}
| |
//+------------------------------------------------------------------+
| |
//| TesterDeinit function |
| |
//+------------------------------------------------------------------+
| |
void OnTesterDeinit()
| |
{
| |
//---
| |
| |
}
| |
//+------------------------------------------------------------------+
| |
//| ChartEvent function |
| |
//+------------------------------------------------------------------+
| |
void OnChartEvent(const int id,
| |
const long &lparam,
| |
const double &dparam,
| |
const string &sparam)
| |
{
| |
//---
| |
| |
}
| |
//+------------------------------------------------------------------+
| |
//| BookEvent function |
| |
//+------------------------------------------------------------------+
| |
void OnBookEvent(const string &symbol)
| |
{
| |
//---
| |
| |
}
| |
| |
---
| |
[L1, L2, L3, L4]
| |
[0, 2, 3]
| |
| |
---
| |
Eliminar L3
| |
- [L1, L2, L4]
| |
Eliminar indice 2
| |
- [0, 3]
| |
| |
| |
| |
*/
| |
//+------------------------------------------------------------------+
| |
#endif // MQLARTICLES_UTILS_FA_EVENTS_MQH
|