#ifndef AI_SESSION_MQH #define AI_SESSION_MQH #include "LabelUtils.mqh" // --------------------------------------------------------------------------- // AISession.mqh — Forex session detection + chart corner label // Asia: 22:00-06:00 UTC | London: 07:00-12:00 UTC | NY: 13:00-17:00 UTC // AMD: Accumulation | Manipulation | Distribution // --------------------------------------------------------------------------- string GetCurrentSession() { datetime now = TimeCurrent(); MqlDateTime dt; TimeToStruct(now, dt); int h = dt.hour; if(h >= 22 || h < 6) return "Asia"; if(h >= 7 && h < 12) return "London"; if(h >= 13 && h < 17) return "NY"; return "Interbank"; } string GetCurrentSessionPhase(const string session_name) { datetime now = TimeCurrent(); MqlDateTime dt; TimeToStruct(now, dt); int h = dt.hour; string session = session_name; if(StringLen(session) == 0) session = GetCurrentSession(); if(session == "Asia") { if(h >= 22 || h < 2) return "A"; if(h >= 2 && h < 4) return "M"; return "D"; } if(session == "London") { if(h >= 7 && h < 9) return "A"; if(h >= 9 && h < 11) return "M"; return "D"; } if(session == "NY") { if(h >= 13 && h < 15) return "A"; if(h >= 15 && h < 16) return "M"; return "D"; } if(h >= 6 && h < 7) return "A"; if(h >= 12 && h < 13) return "M"; if(h >= 17 && h < 22) return "D"; return "A"; } void InitAISession() { GW_Session_Name = GetCurrentSession(); GW_Session_Phase = GetCurrentSessionPhase(GW_Session_Name); GW_Session_Confidence = 0.0; g_symbol_session_name = GW_Session_Name; g_symbol_session_phase = GW_Session_Phase; Last_GW_Session_Update = TimeCurrent(); } void RefreshAISessionState() { string session_name = GetCurrentSession(); string local_phase = GetCurrentSessionPhase(session_name); g_symbol_session_name = session_name; g_symbol_session_phase = local_phase; GW_Session_Name = session_name; if(!GW_Initialized || AI_Mode == "off" || Last_GW_Session_Update == 0 || (TimeCurrent() - Last_GW_Session_Update) > (Session_Phase_Refresh_Seconds * 2)) { GW_Session_Phase = local_phase; if(GW_Session_Confidence <= 0.0) GW_Session_Confidence = 50.0; } else if(StringLen(GW_Session_Phase) == 0) { GW_Session_Phase = local_phase; } } void UpdateSessionLabel() { RefreshAISessionState(); if(!AI_Session_Draw) { ObjectDelete(0, "GW_SESSION_LABEL"); ObjectDelete(0, "GW_NEWS_LABEL"); return; } // Session phase label string phase = StringLen(GW_Session_Phase) > 0 ? GW_Session_Phase : "?"; string sess = StringLen(GW_Session_Name) > 0 ? GW_Session_Name : GetCurrentSession(); string text = " " + sess + " | " + phase; if(GW_Session_Confidence > 0.0) text += " (" + DoubleToString(GW_Session_Confidence, 0) + "%)"; text += " | GW:" + GW_Status; VZ_DrawLabel("GW_SESSION_LABEL", 7, text, VZ_ColorFromPhase(phase), 9); // News headline label (if any) if(StringLen(GW_News_Headlines) > 0) { string ntext = " News: " + StringSubstr(GW_News_Headlines, 0, 100); color ncolor = clrKhaki; if(News_Bias_Direction > 0) ncolor = clrLime; else if(News_Bias_Direction < 0) ncolor = clrRed; else if(News_Bias_Strength >= 70.0) ncolor = clrGold; else if(News_Bias_Strength >= 40.0) ncolor = clrOrange; VZ_DrawLabel("GW_NEWS_LABEL", 8, ntext, ncolor, 8); } } void CleanupSessionLabel() { ObjectDelete(0, "GW_SESSION_LABEL"); ObjectDelete(0, "GW_NEWS_LABEL"); } #endif