ICTLibraryEasy/Src/Concepts/RangeSession.mqh

375 lines
35 KiB
MQL5

2025-12-21 22:11:39 -05:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| RangeSession.mqh |
//| Copyright 2025, Leo. |
//| https://www.mql5.com/es/users/nique_372/news |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, Leo."
#property link "https://www.mql5.com/es/users/nique_372/news"
#property strict
#ifndef ICTLIBRARYEASY_SRC_CONCEPTS_RANGE_SESSION_MQH
#define ICTLIBRARYEASY_SRC_CONCEPTS_RANGE_SESSION_MQH
#include "..\\Base\\Imports.mqh"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//FLUJO DE TRABAJO:
// La clase CRangeSession consta unicamente de una funcoin para esto OnTicktEvent, ahi se ejectua toda la logica
/*
Ejemplo con sesion 10-14
start_hour = 10
start_minute = 0
end_hour = 14
end_minute = 0
P%P%P%P%P%P%P%P%P%P%j%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%j%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%
TIEMPO % EXTERNO (API P<EFBFBD>blica) % INTERNO (Eventos Autom<EFBFBD>ticos)
P%P%P%P%P%P%P%P%P%P%j%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%j%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%
% %
09:59 % IsInitSession() <EFBFBD>! false %
% IsEndSession() <EFBFBD>! false % OnOutOfSession() =<EFBFBD><EFBFBD>
% EnSesion() <EFBFBD>! false %
% %
%%%%%%%%%%<%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
10:00 <EFBFBD>& % IsInitSession() <EFBFBD>! true P+ % OnInitSession() '
% IsEndSession() <EFBFBD>! false % %% Inicializaci<EFBFBD>n de sesi<EFBFBD>n
% EnSesion() <EFBFBD>! true ' % OnSession() '
% % %% Primera actualizaci<EFBFBD>n
% %
%%%%%%%%%%<%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
10:01 % IsInitSession() <EFBFBD>! false % OnSession() '
% IsEndSession() <EFBFBD>! false % %% Actualizaci<EFBFBD>n continua
% EnSesion() <EFBFBD>! true ' %
% %
%%%%%%%%%%<%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
... % IsInitSession() <EFBFBD>! false % OnSession() =<EFBFBD><EFBFBD>
% IsEndSession() <EFBFBD>! false % %% Actualizaci<EFBFBD>n continua
% EnSesion() <EFBFBD>! true ' %
% %
%%%%%%%%%%<%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
13:58 % IsInitSession() <EFBFBD>! false % OnSession() '
% IsEndSession() <EFBFBD>! false % %% Actualizaci<EFBFBD>n continua
% EnSesion() <EFBFBD>! true ' %
% %
%%%%%%%%%%<%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
13:59 % IsInitSession() <EFBFBD>! false % OnSession() '
% IsEndSession() <EFBFBD>! false % %% <EFBFBD>ltima actualizaci<EFBFBD>n directa
% EnSesion() <EFBFBD>! true ' %
% %
%%%%%%%%%%<%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
14:00 <EFBFBD>& % IsInitSession() <EFBFBD>! false % OnEndSession() '
% IsEndSession() <EFBFBD>! true P+ % %% Captura final de datos
% EnSesion() <EFBFBD>! false L' % %% Calcula inicio/fin pr<EFBFBD>xima sesi<EFBFBD>n
% % %% OnSession() (llamada interna)
% % %% Actualizaci<EFBFBD>n final max/min
% %
%%%%%%%%%%<%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
14:01 % IsInitSession() <EFBFBD>! false % OnOutOfSession() =<EFBFBD><EFBFBD>
% IsEndSession() <EFBFBD>! false % %% Fuera de sesi<EFBFBD>n
% EnSesion() <EFBFBD>! false %
% %
P%P%P%P%P%P%P%P%P%P%g%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%g%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%P%
LEYENDA:
<EFBFBD>& = Momento cr<EFBFBD>tico (inicio/fin de sesi<EFBFBD>n)
P+ = Flag temporal (true solo en ese minuto)
' = Ejecuci<EFBFBD>n/Estado activo
L' = Estado inactivo
=<EFBFBD><EFBFBD> = Ejecuci<EFBFBD>n repetitiva
Notas:
" EnSesion() retorna true durante [10:00, 13:59] (NO incluye 14:00)
" IsEndSession() retorna true SOLO a las 14:00 (flag temporal)
" Para incluir el <00>ltimo minuto en l<00>gica: usar EnSesion() || IsEndSession()
" A las 14:00, OnEndSession() llama internamente a OnSession() para captura final*
*Depende del tipo de sesion (CRangeSession)
*/
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class CRangeSession : public CLoggerBase
{
private:
int m_handle;
//---
void Destroy();
public:
CRangeSession();
~CRangeSession();
//---
bool Create(string symbol_, ENUM_TIMEFRAMES timeframe_, long chart_id_, int subwin_, bool show_concept_, bool forzar_lunes_viernes_
, int start_hour_, int start_minute_, int end_hour_, int end_minute_, string session_name_);
//---
inline void SetGrapichStyles(ENUM_LINE_STYLE rect_style_, color clr_rect_, int widht_rect_, bool fill_rect_);
inline void Set(int widht_lines_, ENUM_LINE_STYLE style_lines_, color clr_lines_max, color clr_line_min, color clr_text,
ENUM_TYPE_DRAW_SESSION_TEXT type_text_, ENUM_TYPE_DRAW_RANGE_SESSION type_draw);
//---
inline bool ShowAll() ;
inline bool HideAll() ;
inline bool DeleteAll() ;
inline void SetFlagMostrarObjetos(bool mostrar) ;
inline void ForzeToActulizeCurrentTick() ;
inline bool IsNewBarConcept() { return ICTRangeSession_IsNewBarConcept(m_handle); }
//---
inline double GetMaxSession(); //Obtiene el maximo de la sesion
inline double GetMinSession(); //Obtiene el minimo de la sesion
inline double GetRangeSession(); //Obtiene la altura de la session (maximo - minimo) en distanica NO en puntos
inline datetime GetInitTimeSessionCurrNext(); //Obtiene el inicio de la sesion (Actual si se llama durante la sesion, y siguiente si se llama depues de la sesion)
inline datetime GetEndTimeSessionCurrNext(); //Obtiene el fin de la sesion (Actual si se llama durante la sesion, y siguiente si se llama depues de la sesion)
inline datetime GetInitTimeSessionPrev(); //Obtiene el inicio de la sesion previa
inline datetime GetEndTimeSessionPrev(); //Obtiene el final de la sesino previa
inline int GetDuracionSessionSegundos(); //Obtiene la durancion en segundos de la sesion
inline int GetDuracionSessionMinutos(); //Obtiene la durancion en minutos de la sesion
inline bool IsInitSession(); //Devuelve true, si ha comenzado la sesion (ESTA FUNCION UNICAMENTE DEVUELVE TRUE UNA SOLA VEZ, AL INICIO DE LA SESION, LUEGO FALSE)
inline bool IsEndSession(); //Devuelve true, si ha finalizado la sesion (ESTA FUNCION UNICAMENTE DEVUELVE TRUE UNA SOLA VEZ, AL FIN DE LA SESION, LUEGO FALSE)
inline bool EnSesion(); //Comprueba si estamos en la sesion, true, o de lo contrario false
2026-01-06 16:54:20 -05:00
inline void OnNewBarM1(); //Ejecuta la logica principal
2025-12-21 22:11:39 -05:00
inline string GetSessionName(); //Obtiene el nombre de la sesion
inline int8_t GetSessionInfo(datetime init_day, SessionInfo &out, string _symbol); // Obtinee la infomacion de una sesion pasada o futura
//---
inline void AddLogFlags(const uint8_t flags) { ICTRangeSession_AddLogFlags(m_handle, flags); CLoggerBase::AddLogFlags(flags); }
void RemoveLogFlags(const uint8_t flags) { ICTRangeSession_RemoveLogFlags(m_handle, flags); CLoggerBase::RemoveLogFlags(flags); }
//---
inline int Handle() const { return m_handle; }
inline string Symbol() const { return ICTRangeSession_Simbolo(m_handle); }
inline ENUM_TIMEFRAMES Timeframe() const { return ICTRangeSession_Timeframe(m_handle); }
inline long ChartId() const { return ICTRangeSession_ChartId(m_handle); }
inline int Subwin() const { return ICTRangeSession_Subwin(m_handle); }
inline bool InitialStateObj() const { return ICTRangeSession_GetInittialStateObj(m_handle); }
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
CRangeSession::CRangeSession()
: m_handle(INVALID_HANDLE)
{
}
//+------------------------------------------------------------------+
CRangeSession::~CRangeSession()
{
Destroy();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//- forzar_lunes_vierens_ : Le indica a la clase que la clase solo trabajara de lunes a viernes. (Normalente en crypto es de L -D, por lo que en ese caso si este parametro es false
//- La clase trabajra de L - D, de lo contrario solo de L - V)
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CRangeSession::Create(string symbol_, ENUM_TIMEFRAMES timeframe_, long chart_id_, int subwin_, bool show_concept_, bool forzar_lunes_viernes_
, int start_hour_, int start_minute_, int end_hour_, int end_minute_, string session_name_)
{
if(m_handle != INVALID_HANDLE)
Destroy();
//---
m_handle = ICTRangeSession_Create(symbol_, timeframe_, chart_id_, subwin_, show_concept_, forzar_lunes_viernes_, start_hour_, start_minute_, end_hour_, end_minute_, session_name_);
//---
if(m_handle >= 0)
{
return true;
}
else
{
LogError("No se pudo crear un m_handle para CRangeSession", FUNCION_ACTUAL);
Remover();
}
//---
return false;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
inline void CRangeSession::SetGrapichStyles(ENUM_LINE_STYLE rect_style_, color clr_rect_, int widht_rect_, bool fill_rect_)
{
ICTRangeSession_SetGrapichStyles(m_handle, rect_style_, clr_rect_, widht_rect_, fill_rect_);
}
//+------------------------------------------------------------------+
inline void CRangeSession::Set(int widht_lines_, ENUM_LINE_STYLE style_lines_, color clr_lines_max, color clr_line_min, color clr_text,
ENUM_TYPE_DRAW_SESSION_TEXT type_text_, ENUM_TYPE_DRAW_RANGE_SESSION type_draw)
{
ICTRangeSession_Set(m_handle, widht_lines_, style_lines_, clr_lines_max, clr_line_min, clr_text, type_text_, type_draw);
}
//+------------------------------------------------------------------+
inline bool CRangeSession::ShowAll()
{
return ICTRangeSession_ShowAll(m_handle);
}
//+------------------------------------------------------------------+
inline bool CRangeSession::HideAll()
{
return ICTRangeSession_HideAll(m_handle);
}
//+------------------------------------------------------------------+
inline bool CRangeSession::DeleteAll()
{
return ICTRangeSession_DeleteAll(m_handle);
}
//+------------------------------------------------------------------+
inline void CRangeSession::SetFlagMostrarObjetos(bool mostrar)
{
ICTRangeSession_SetFlagMostrarObjetos(m_handle, mostrar);
}
//+------------------------------------------------------------------+
inline void CRangeSession::ForzeToActulizeCurrentTick()
{
ICTRangeSession_ForzeToActulizeCurrentTick(m_handle);
}
//+------------------------------------------------------------------+
inline double CRangeSession::GetMaxSession()
{
return ICTRangeSession_GetMaxSession(m_handle);
}
//+------------------------------------------------------------------+
inline double CRangeSession::GetMinSession()
{
return ICTRangeSession_GetMinSession(m_handle);
}
//+------------------------------------------------------------------+
inline double CRangeSession::GetRangeSession()
{
return ICTRangeSession_GetRangeSession(m_handle);
}
//+------------------------------------------------------------------+
inline datetime CRangeSession::GetInitTimeSessionCurrNext()
{
return ICTRangeSession_GetInitTimeSessionCurrNext(m_handle);
}
//+------------------------------------------------------------------+
inline datetime CRangeSession::GetEndTimeSessionCurrNext()
{
return ICTRangeSession_GetEndTimeSessionCurrNext(m_handle);
}
//+------------------------------------------------------------------+
inline datetime CRangeSession::GetInitTimeSessionPrev()
{
return ICTRangeSession_GetInitTimeSessionPrev(m_handle);
}
//+------------------------------------------------------------------+
inline datetime CRangeSession::GetEndTimeSessionPrev()
{
return ICTRangeSession_GetEndTimeSessionPrev(m_handle);
}
//+------------------------------------------------------------------+
inline int CRangeSession::GetDuracionSessionSegundos()
{
return ICTRangeSession_GetDuracionSessionSegundos(m_handle);
}
//+------------------------------------------------------------------+
inline int CRangeSession::GetDuracionSessionMinutos()
{
return ICTRangeSession_GetDuracionSessionMinutos(m_handle);
}
//+------------------------------------------------------------------+
inline bool CRangeSession::IsInitSession()
{
return ICTRangeSession_IsInitSession(m_handle);
}
//+------------------------------------------------------------------+
inline bool CRangeSession::IsEndSession()
{
return ICTRangeSession_IsEndSession(m_handle);
}
//+------------------------------------------------------------------+
inline bool CRangeSession::EnSesion()
{
return ICTRangeSession_EnSesion(m_handle);
}
//+------------------------------------------------------------------+
2026-01-06 16:54:20 -05:00
inline void CRangeSession::OnNewBarM1()
2025-12-21 22:11:39 -05:00
{
2026-01-06 16:54:20 -05:00
ICTRangeSession_OnNewBarM1(m_handle);
2025-12-21 22:11:39 -05:00
}
//+------------------------------------------------------------------+
inline string CRangeSession::GetSessionName()
{
return ICTRangeSession_GetSessionName(m_handle);
}
//+----------------------------------------------------------------------------------+
//| Obtiene la informacion de una sesion en base al inicio del dia |
//| Inputs: |
//| - init_day: Dia en el cual se quiere obtener informacion (fecha - datetime) |
//| - out: Estructura del tipo SessionInfo, en la cual se obtendra la informacion |
//| - _symbol: Simbolo en la cual se buscara el maximo y minimo de la sesion |
//| Outputs: |
//| - int8_t: La funcion tiene pensado estos valores de retorno |
//| SESSION_INFO_SUCCESS - 0: Se obtuvo el maximo, minimo, fecha de inicio y fin |
//| de la sesino exitosamente. |
//| SESSION_INFO_PARTIAL - 1: Se obtuvo parcialmente la info del maximo y minimo |
//| , pero si se obtuvo informacion del inicio y fin |
//| de la sesion |
//| |
//| SESSION_INFO_FUTURE - 2: Solo se obtuvo el inicio y fin de la sesion |
//| Dado que la seison es futura. |
//| |
//+----------------------------------------------------------------------------------+
inline int8_t CRangeSession::GetSessionInfo(datetime init_day, SessionInfo &out, string _symbol)
{
return ICTRangeSession_GetSessionInfo(m_handle, init_day, out, _symbol);
}
//+------------------------------------------------------------------+
void CRangeSession::Destroy()
{
if(m_handle != INVALID_HANDLE)
{
ICTRangeSession_Delete(m_handle);
m_handle = INVALID_HANDLE;
}
}
#endif // ICTLIBRARYEASY_SRC_CONCEPTS_RANGE_SESSION_MQH
//+------------------------------------------------------------------+