forked from nique_372/MQLArticles
180 lines
7.2 KiB
MQL5
180 lines
7.2 KiB
MQL5
//+------------------------------------------------------------------+
| |
//| 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
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
#include "..\\..\\..\\TimeUtils\\TimeUtils.mqh"
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
namespace TSN
| |
{
| |
//+------------------------------------------------------------------+
| |
//| Clase para filtrar por año |
| |
//+------------------------------------------------------------------+
| |
class CYearFilter
| |
{
| |
private:
| |
// Arreglo para almacenar el estado de cada mes (true = habilitado)
| |
bool m_months[12];
| |
| |
public:
| |
CYearFilter(void);
| |
~CYearFilter(void);
| |
| |
// Mé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);
| |
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]; }
| |
| |
// Octubre
| |
inline bool Octubre(bool value) { return (m_months[9] = value); }
| |
__forceinline bool Octubre() const { return m_months[9]; }
| |
| |
// 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
| |
// Verificar si el mes actual es un mes de operación (optimizado para rendimiento)
| |
__forceinline bool IsMonthTrade() const;
| |
| |
// Verificar si un mes específico es un mes de operación (sobrecarga para una fecha concreta)
| |
__forceinline bool IsMonthTrade(datetime time) const;
| |
| |
// 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ón |
| |
//+------------------------------------------------------------------+
| |
__forceinline bool CYearFilter::IsMonthTrade() const
| |
{
| |
return IsMonthTrade(TimeCurrent());
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| Verificar si un mes específico es un mes de operación |
| |
//+------------------------------------------------------------------+
| |
__forceinline bool CYearFilter::IsMonthTrade(datetime time) const
| |
{
| |
return m_months[CTimeUtils::Month(time) - 1];
| |
}
| |
}
| |
//+------------------------------------------------------------------+
| |
#endif // MQLARTILES_STRATEGY_UTILS_YEARFILTER_MQH
|