| //+------------------------------------------------------------------+
|
| //| 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 ICTLIBRARY_CONCEPTS_SESION_RANGE_SESSION_MQH
|
| #define ICTLIBRARY_CONCEPTS_SESION_RANGE_SESSION_MQH
|
| #include "..\\Base.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
|
|
|
| ══════════╪══════════════════════════════════════════╪═══════════════════════════════════════
|
| TIEMPO │ EXTERNO (API Pública) │ INTERNO (Eventos Automáticos)
|
| ══════════╪══════════════════════════════════════════╪═══════════════════════════════════════
|
| │ │
|
| 09:59 │ IsInitSession() → false │
|
| │ IsEndSession() → false │ OnOutOfSession() 🔄
|
| │ EnSesion() → false │
|
| │ │
|
| ──────────┼──────────────────────────────────────────┼───────────────────────────────────────
|
| │ │
|
| 10:00 ⚡ │ IsInitSession() → true ⭐ │ OnInitSession() ✅
|
| │ IsEndSession() → false │ └─ Inicialización de sesión
|
| │ EnSesion() → true ✅ │ OnSession() ✅
|
| │ │ └─ Primera actualización
|
| │ │
|
| ──────────┼──────────────────────────────────────────┼───────────────────────────────────────
|
| │ │
|
| 10:01 │ IsInitSession() → false │ OnSession() ✅
|
| │ IsEndSession() → false │ └─ Actualización continua
|
| │ EnSesion() → true ✅ │
|
| │ │
|
| ──────────┼──────────────────────────────────────────┼───────────────────────────────────────
|
| │ │
|
| ... │ IsInitSession() → false │ OnSession() 🔄
|
| │ IsEndSession() → false │ └─ Actualización continua
|
| │ EnSesion() → true ✅ │
|
| │ │
|
| ──────────┼──────────────────────────────────────────┼───────────────────────────────────────
|
| │ │
|
| 13:58 │ IsInitSession() → false │ OnSession() ✅
|
| │ IsEndSession() → false │ └─ Actualización continua
|
| │ EnSesion() → true ✅ │
|
| │ │
|
| ──────────┼──────────────────────────────────────────┼───────────────────────────────────────
|
| │ │
|
| 13:59 │ IsInitSession() → false │ OnSession() ✅
|
| │ IsEndSession() → false │ └─ Última actualización directa
|
| │ EnSesion() → true ✅ │
|
| │ │
|
| ──────────┼──────────────────────────────────────────┼───────────────────────────────────────
|
| │ │
|
| 14:00 ⚡ │ IsInitSession() → false │ OnEndSession() ✅
|
| │ IsEndSession() → true ⭐ │ ├─ Captura final de datos
|
| │ EnSesion() → false ❌ │ ├─ Calcula inicio/fin próxima sesión
|
| │ │ └─ OnSession() (llamada interna)
|
| │ │ └─ Actualización final max/min
|
| │ │
|
| ──────────┼──────────────────────────────────────────┼───────────────────────────────────────
|
| │ │
|
| 14:01 │ IsInitSession() → false │ OnOutOfSession() 🔄
|
| │ IsEndSession() → false │ └─ Fuera de sesión
|
| │ EnSesion() → false │
|
| │ │
|
| ══════════╧══════════════════════════════════════════╧═══════════════════════════════════════
|
|
|
| LEYENDA:
|
| ⚡ = Momento crítico (inicio/fin de sesión)
|
| ⭐ = Flag temporal (true solo en ese minuto)
|
| ✅ = Ejecución/Estado activo
|
| ❌ = Estado inactivo
|
| 🔄 = Ejecució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 último minuto en ló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 IIctConcept
|
| {
|
| 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() override final;
|
| inline bool HideAll() override final;
|
| inline bool DeleteAll() override final;
|
| inline void SetFlagMostrarObjetos(bool mostrar) override final;
|
| inline void ForzeToActulizeCurrentTick() override final;
|
| inline bool IsNewBarConcept() override final { 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
|
| inline void OnNewBarM1(); //Ejecuta la logica principal
|
| 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 uint8_t CurrState() { return ICTRangeSession_CurrState(m_handle); }
|
|
|
| //---
|
| inline void AddLogFlags(const uint8_t flags) override final { ICTRangeSession_AddLogFlags(m_handle, flags); CLoggerBase::AddLogFlags(flags); }
|
| void RemoveLogFlags(const uint8_t flags) override final { ICTRangeSession_RemoveLogFlags(m_handle, flags); CLoggerBase::RemoveLogFlags(flags); }
|
|
|
| //---
|
| inline int Handle() const override final { return m_handle; }
|
| inline string Symbol() const override final { return ICTRangeSession_Simbolo(m_handle); }
|
| inline ENUM_TIMEFRAMES Timeframe() const override final { return ICTRangeSession_Timeframe(m_handle); }
|
| inline long ChartId() const override final { return ICTRangeSession_ChartId(m_handle); }
|
| inline int Subwin() const override final { return ICTRangeSession_Subwin(m_handle); }
|
| inline bool InitialStateObj() const override final { return ICTRangeSession_GetInittialStateObj(m_handle); }
|
|
|
| inline uint8_t ModifyFlags() const override final { return ICTRangeSession_ModifyFlags(m_handle); }
|
| inline bool GetStateObj() const override final { return ICTRangeSession_GetStateObj(m_handle); }
|
| inline void Summary() const override final { ICTRangeSession_Summary(m_handle); }
|
| inline void ChangeChart(long new_chart_id, int new_subwin) override final { ICTRangeSession_ChangeChart(m_handle, new_chart_id, new_subwin); }
|
|
|
| };
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| 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);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| inline void CRangeSession::OnNewBarM1()
|
| {
|
| ICTRangeSession_OnNewBarM1(m_handle);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| 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 // ICTLIBRARY_CONCEPTS_SESION_RANGE_SESSION_MQH
|
| //+------------------------------------------------------------------+
|