MQLArticles/Strategy/Utils/YearFilter.mqh

176 righe
14 KiB
MQL5

2025-12-05 16:33:47 -05:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| YearFilter.mqh |
//| Copyright 2025, Leo. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, Leo."
#property link "https://www.mql5.com"
#property strict
#ifndef MQLARTILES_STRATEGY_UTILS_YEARFILTER_MQH
#define MQLARTILES_STRATEGY_UTILS_YEARFILTER_MQH
//+------------------------------------------------------------------+
2025-12-28 18:28:41 -05:00
//| |
//+------------------------------------------------------------------+
#include "..\\..\\..\\TimeUtils\\TimeUtils.mqh"
//+------------------------------------------------------------------+
2025-12-05 16:33:47 -05:00
//| Clase para filtrar por a<EFBFBD>o |
//+------------------------------------------------------------------+
class CYearFilter
{
private:
// Arreglo para almacenar el estado de cada mes (true = habilitado)
bool m_months[12];
public:
CYearFilter(void);
~CYearFilter(void);
// M<EFBFBD>todos para configurar todos los meses a la vez
void Set(bool enero, bool febrero, bool marzo, bool abril, bool mayo, bool junio,
bool julio, bool agosto, bool septiembre, bool octubre, bool noviembre, bool diciembre);
2025-12-28 18:28:41 -05:00
void Set(const bool& arr[], int src_start = 0) { ArrayCopy(m_months, arr, 0, src_start, 12); }
//--- Setters y Getters generales
// Enero
inline bool Enero(bool value) { return (m_months[0] = value); }
__forceinline bool Enero() const { return m_months[0]; }
// Febrero
inline bool Febrero(bool value) { return (m_months[1] = value); }
__forceinline bool Febrero() const { return m_months[1]; }
// Marzo
inline bool Marzo(bool value) { return (m_months[2] = value); }
__forceinline bool Marzo() const { return m_months[2]; }
// Abril
inline bool Abril(bool value) { return (m_months[3] = value); }
__forceinline bool Abril() const { return m_months[3]; }
// Mayo
inline bool Mayo(bool value) { return (m_months[4] = value); }
__forceinline bool Mayo() const { return m_months[4]; }
// Junio
inline bool Junio(bool value) { return (m_months[5] = value); }
__forceinline bool Junio() const { return m_months[5]; }
// Julio
inline bool Julio(bool value) { return (m_months[6] = value); }
__forceinline bool Julio() const { return m_months[6]; }
// Agosto
inline bool Agosto(bool value) { return (m_months[7] = value); }
__forceinline bool Agosto() const { return m_months[7]; }
// Septiembre
inline bool Septiembre(bool value) { return (m_months[8] = value); }
__forceinline bool Septiembre() const { return m_months[8]; }
2025-12-05 16:33:47 -05:00
2025-12-28 18:28:41 -05:00
// Octubre
inline bool Octubre(bool value) { return (m_months[9] = value); }
__forceinline bool Octubre() const { return m_months[9]; }
2025-12-05 16:33:47 -05:00
2025-12-28 18:28:41 -05:00
// Noviembre
inline bool Noviembre(bool value) { return (m_months[10] = value); }
__forceinline bool Noviembre() const { return m_months[10]; }
// Diciembre
inline bool Diciembre(bool value) { return (m_months[11] = value); }
__forceinline bool Diciembre() const { return m_months[11]; }
// Mes (Indice interno 1-12, Enero=1, Febrrero=2)
__forceinline bool Month(int month, bool value) { return (m_months[month - 1] = value); }
__forceinline bool Month(int month) const { return (m_months[month - 1]); }
//--- General
2025-12-05 16:33:47 -05:00
// Verificar si el mes actual es un mes de operaci<EFBFBD>n (optimizado para rendimiento)
2025-12-28 18:28:41 -05:00
__forceinline bool IsMonthTrade() const;
2025-12-05 16:33:47 -05:00
// Verificar si un mes espec<EFBFBD>fico es un mes de operaci<EFBFBD>n (sobrecarga para una fecha concreta)
2025-12-28 18:28:41 -05:00
__forceinline bool IsMonthTrade(datetime time) const;
2025-12-05 16:33:47 -05:00
// Habilitar todos los meses
inline void EnableAll();
// Deshabilitar todos los meses
inline void DisableAll();
};
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CYearFilter::CYearFilter(void)
{
// Por defecto, habilitar todos los meses
EnableAll();
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CYearFilter::~CYearFilter(void)
{
// No se requieren acciones especiales
}
//+------------------------------------------------------------------+
//| Habilitar todos los meses |
//+------------------------------------------------------------------+
inline void CYearFilter::EnableAll()
{
for(int i = 0; i < 12; i++)
m_months[i] = true;
}
//+------------------------------------------------------------------+
//| Deshabilitar todos los meses |
//+------------------------------------------------------------------+
inline void CYearFilter::DisableAll()
{
for(int i = 0; i < 12; i++)
m_months[i] = false;
}
//+------------------------------------------------------------------+
//| Establecer todos los meses de una vez |
//+------------------------------------------------------------------+
void CYearFilter::Set(bool enero, bool febrero, bool marzo, bool abril, bool mayo, bool junio,
bool julio, bool agosto, bool septiembre, bool octubre, bool noviembre, bool diciembre)
{
m_months[0] = enero;
m_months[1] = febrero;
m_months[2] = marzo;
m_months[3] = abril;
m_months[4] = mayo;
m_months[5] = junio;
m_months[6] = julio;
m_months[7] = agosto;
m_months[8] = septiembre;
m_months[9] = octubre;
m_months[10] = noviembre;
m_months[11] = diciembre;
}
//+------------------------------------------------------------------+
//| Verificar si el mes actual es un mes de operaci<EFBFBD>n |
//+------------------------------------------------------------------+
2025-12-28 18:28:41 -05:00
__forceinline bool CYearFilter::IsMonthTrade() const
2025-12-05 16:33:47 -05:00
{
2025-12-28 18:28:41 -05:00
return IsMonthTrade(TimeCurrent());
2025-12-05 16:33:47 -05:00
}
//+------------------------------------------------------------------+
//| Verificar si un mes espec<EFBFBD>fico es un mes de operaci<EFBFBD>n |
//+------------------------------------------------------------------+
2025-12-28 18:28:41 -05:00
__forceinline bool CYearFilter::IsMonthTrade(datetime time) const
2025-12-05 16:33:47 -05:00
{
2025-12-28 18:28:41 -05:00
return m_months[CTimeUtils::GetMonth(time) - 1];
2025-12-05 16:33:47 -05:00
}
//+------------------------------------------------------------------+
2025-12-28 18:28:41 -05:00
#endif // MQLARTILES_STRATEGY_UTILS_YEARFILTER_MQH