feat: replace OpenAI with n8n AI Gateway + session + watchlist
- Remove OpenAI.mqh entirely (no direct API calls)
- Add AIGateway.mqh: unified gateway → n8n → OpenRouter → Claude
- advisory mode: EA never fails to start (gateway down = MAYBE 0.5x)
- mandatory mode: blocks trades if gateway unreachable
- actions: validate_trade, get_briefing, get_session, get_news_bias,
report_trade, watchlist_status, ping
- includes bid/est_sl/est_tp in validate_trade payload
- Add AISession.mqh: AMD session detection (Asia/London/NY/Interbank)
with corner chart labels showing session phase + GW status
- InputParams.mqh: AI_Mode, AI_Gateway_URL, briefing TF flags,
AI_Session_Draw, Use_Watchlist_Gate
- GlobalVariables.mqh: gateway state, per-TF briefing cache,
session + news headlines globals
- MasterAICoordinator.mqh: wired to AIGateway (SetUseOpenAI shim kept)
- NewsEngine.mqh: merges live AI news bias from gateway
- AISignalConfirmation.mqh: delegates to AIValidateTrade()
- AILabels.mqh: GW status (color-coded), validation stats, per-TF briefs
- ChartLabels.mqh: session label integration
- profitgtx.mq5 v7.00: OnInit init gateway + session, OnTimer multi-TF
briefing refresh, OnTradeTransaction fire-and-forget trade report
- Recompile: 0 errors, 0 warnings
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-20 06:34:27 +00:00
|
|
|
#ifndef AI_SESSION_MQH
|
|
|
|
|
#define AI_SESSION_MQH
|
|
|
|
|
|
2026-03-31 02:57:33 +00:00
|
|
|
#include "LabelUtils.mqh"
|
|
|
|
|
|
feat: replace OpenAI with n8n AI Gateway + session + watchlist
- Remove OpenAI.mqh entirely (no direct API calls)
- Add AIGateway.mqh: unified gateway → n8n → OpenRouter → Claude
- advisory mode: EA never fails to start (gateway down = MAYBE 0.5x)
- mandatory mode: blocks trades if gateway unreachable
- actions: validate_trade, get_briefing, get_session, get_news_bias,
report_trade, watchlist_status, ping
- includes bid/est_sl/est_tp in validate_trade payload
- Add AISession.mqh: AMD session detection (Asia/London/NY/Interbank)
with corner chart labels showing session phase + GW status
- InputParams.mqh: AI_Mode, AI_Gateway_URL, briefing TF flags,
AI_Session_Draw, Use_Watchlist_Gate
- GlobalVariables.mqh: gateway state, per-TF briefing cache,
session + news headlines globals
- MasterAICoordinator.mqh: wired to AIGateway (SetUseOpenAI shim kept)
- NewsEngine.mqh: merges live AI news bias from gateway
- AISignalConfirmation.mqh: delegates to AIValidateTrade()
- AILabels.mqh: GW status (color-coded), validation stats, per-TF briefs
- ChartLabels.mqh: session label integration
- profitgtx.mq5 v7.00: OnInit init gateway + session, OnTimer multi-TF
briefing refresh, OnTradeTransaction fire-and-forget trade report
- Recompile: 0 errors, 0 warnings
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-20 06:34:27 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
// 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";
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 02:57:33 +00:00
|
|
|
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";
|
|
|
|
|
}
|
|
|
|
|
|
feat: replace OpenAI with n8n AI Gateway + session + watchlist
- Remove OpenAI.mqh entirely (no direct API calls)
- Add AIGateway.mqh: unified gateway → n8n → OpenRouter → Claude
- advisory mode: EA never fails to start (gateway down = MAYBE 0.5x)
- mandatory mode: blocks trades if gateway unreachable
- actions: validate_trade, get_briefing, get_session, get_news_bias,
report_trade, watchlist_status, ping
- includes bid/est_sl/est_tp in validate_trade payload
- Add AISession.mqh: AMD session detection (Asia/London/NY/Interbank)
with corner chart labels showing session phase + GW status
- InputParams.mqh: AI_Mode, AI_Gateway_URL, briefing TF flags,
AI_Session_Draw, Use_Watchlist_Gate
- GlobalVariables.mqh: gateway state, per-TF briefing cache,
session + news headlines globals
- MasterAICoordinator.mqh: wired to AIGateway (SetUseOpenAI shim kept)
- NewsEngine.mqh: merges live AI news bias from gateway
- AISignalConfirmation.mqh: delegates to AIValidateTrade()
- AILabels.mqh: GW status (color-coded), validation stats, per-TF briefs
- ChartLabels.mqh: session label integration
- profitgtx.mq5 v7.00: OnInit init gateway + session, OnTimer multi-TF
briefing refresh, OnTradeTransaction fire-and-forget trade report
- Recompile: 0 errors, 0 warnings
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-20 06:34:27 +00:00
|
|
|
void InitAISession()
|
|
|
|
|
{
|
|
|
|
|
GW_Session_Name = GetCurrentSession();
|
2026-03-31 02:57:33 +00:00
|
|
|
GW_Session_Phase = GetCurrentSessionPhase(GW_Session_Name);
|
feat: replace OpenAI with n8n AI Gateway + session + watchlist
- Remove OpenAI.mqh entirely (no direct API calls)
- Add AIGateway.mqh: unified gateway → n8n → OpenRouter → Claude
- advisory mode: EA never fails to start (gateway down = MAYBE 0.5x)
- mandatory mode: blocks trades if gateway unreachable
- actions: validate_trade, get_briefing, get_session, get_news_bias,
report_trade, watchlist_status, ping
- includes bid/est_sl/est_tp in validate_trade payload
- Add AISession.mqh: AMD session detection (Asia/London/NY/Interbank)
with corner chart labels showing session phase + GW status
- InputParams.mqh: AI_Mode, AI_Gateway_URL, briefing TF flags,
AI_Session_Draw, Use_Watchlist_Gate
- GlobalVariables.mqh: gateway state, per-TF briefing cache,
session + news headlines globals
- MasterAICoordinator.mqh: wired to AIGateway (SetUseOpenAI shim kept)
- NewsEngine.mqh: merges live AI news bias from gateway
- AISignalConfirmation.mqh: delegates to AIValidateTrade()
- AILabels.mqh: GW status (color-coded), validation stats, per-TF briefs
- ChartLabels.mqh: session label integration
- profitgtx.mq5 v7.00: OnInit init gateway + session, OnTimer multi-TF
briefing refresh, OnTradeTransaction fire-and-forget trade report
- Recompile: 0 errors, 0 warnings
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-20 06:34:27 +00:00
|
|
|
GW_Session_Confidence = 0.0;
|
2026-03-31 02:57:33 +00:00
|
|
|
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;
|
|
|
|
|
}
|
feat: replace OpenAI with n8n AI Gateway + session + watchlist
- Remove OpenAI.mqh entirely (no direct API calls)
- Add AIGateway.mqh: unified gateway → n8n → OpenRouter → Claude
- advisory mode: EA never fails to start (gateway down = MAYBE 0.5x)
- mandatory mode: blocks trades if gateway unreachable
- actions: validate_trade, get_briefing, get_session, get_news_bias,
report_trade, watchlist_status, ping
- includes bid/est_sl/est_tp in validate_trade payload
- Add AISession.mqh: AMD session detection (Asia/London/NY/Interbank)
with corner chart labels showing session phase + GW status
- InputParams.mqh: AI_Mode, AI_Gateway_URL, briefing TF flags,
AI_Session_Draw, Use_Watchlist_Gate
- GlobalVariables.mqh: gateway state, per-TF briefing cache,
session + news headlines globals
- MasterAICoordinator.mqh: wired to AIGateway (SetUseOpenAI shim kept)
- NewsEngine.mqh: merges live AI news bias from gateway
- AISignalConfirmation.mqh: delegates to AIValidateTrade()
- AILabels.mqh: GW status (color-coded), validation stats, per-TF briefs
- ChartLabels.mqh: session label integration
- profitgtx.mq5 v7.00: OnInit init gateway + session, OnTimer multi-TF
briefing refresh, OnTradeTransaction fire-and-forget trade report
- Recompile: 0 errors, 0 warnings
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-20 06:34:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateSessionLabel()
|
|
|
|
|
{
|
2026-03-31 02:57:33 +00:00
|
|
|
RefreshAISessionState();
|
|
|
|
|
|
feat: replace OpenAI with n8n AI Gateway + session + watchlist
- Remove OpenAI.mqh entirely (no direct API calls)
- Add AIGateway.mqh: unified gateway → n8n → OpenRouter → Claude
- advisory mode: EA never fails to start (gateway down = MAYBE 0.5x)
- mandatory mode: blocks trades if gateway unreachable
- actions: validate_trade, get_briefing, get_session, get_news_bias,
report_trade, watchlist_status, ping
- includes bid/est_sl/est_tp in validate_trade payload
- Add AISession.mqh: AMD session detection (Asia/London/NY/Interbank)
with corner chart labels showing session phase + GW status
- InputParams.mqh: AI_Mode, AI_Gateway_URL, briefing TF flags,
AI_Session_Draw, Use_Watchlist_Gate
- GlobalVariables.mqh: gateway state, per-TF briefing cache,
session + news headlines globals
- MasterAICoordinator.mqh: wired to AIGateway (SetUseOpenAI shim kept)
- NewsEngine.mqh: merges live AI news bias from gateway
- AISignalConfirmation.mqh: delegates to AIValidateTrade()
- AILabels.mqh: GW status (color-coded), validation stats, per-TF briefs
- ChartLabels.mqh: session label integration
- profitgtx.mq5 v7.00: OnInit init gateway + session, OnTimer multi-TF
briefing refresh, OnTradeTransaction fire-and-forget trade report
- Recompile: 0 errors, 0 warnings
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-20 06:34:27 +00:00
|
|
|
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;
|
|
|
|
|
|
2026-03-31 02:57:33 +00:00
|
|
|
VZ_DrawLabel("GW_SESSION_LABEL", 7, text, VZ_ColorFromPhase(phase), 9);
|
feat: replace OpenAI with n8n AI Gateway + session + watchlist
- Remove OpenAI.mqh entirely (no direct API calls)
- Add AIGateway.mqh: unified gateway → n8n → OpenRouter → Claude
- advisory mode: EA never fails to start (gateway down = MAYBE 0.5x)
- mandatory mode: blocks trades if gateway unreachable
- actions: validate_trade, get_briefing, get_session, get_news_bias,
report_trade, watchlist_status, ping
- includes bid/est_sl/est_tp in validate_trade payload
- Add AISession.mqh: AMD session detection (Asia/London/NY/Interbank)
with corner chart labels showing session phase + GW status
- InputParams.mqh: AI_Mode, AI_Gateway_URL, briefing TF flags,
AI_Session_Draw, Use_Watchlist_Gate
- GlobalVariables.mqh: gateway state, per-TF briefing cache,
session + news headlines globals
- MasterAICoordinator.mqh: wired to AIGateway (SetUseOpenAI shim kept)
- NewsEngine.mqh: merges live AI news bias from gateway
- AISignalConfirmation.mqh: delegates to AIValidateTrade()
- AILabels.mqh: GW status (color-coded), validation stats, per-TF briefs
- ChartLabels.mqh: session label integration
- profitgtx.mq5 v7.00: OnInit init gateway + session, OnTimer multi-TF
briefing refresh, OnTradeTransaction fire-and-forget trade report
- Recompile: 0 errors, 0 warnings
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-20 06:34:27 +00:00
|
|
|
|
|
|
|
|
// News headline label (if any)
|
|
|
|
|
if(StringLen(GW_News_Headlines) > 0)
|
|
|
|
|
{
|
|
|
|
|
string ntext = " News: " + StringSubstr(GW_News_Headlines, 0, 100);
|
2026-03-31 02:57:33 +00:00
|
|
|
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);
|
feat: replace OpenAI with n8n AI Gateway + session + watchlist
- Remove OpenAI.mqh entirely (no direct API calls)
- Add AIGateway.mqh: unified gateway → n8n → OpenRouter → Claude
- advisory mode: EA never fails to start (gateway down = MAYBE 0.5x)
- mandatory mode: blocks trades if gateway unreachable
- actions: validate_trade, get_briefing, get_session, get_news_bias,
report_trade, watchlist_status, ping
- includes bid/est_sl/est_tp in validate_trade payload
- Add AISession.mqh: AMD session detection (Asia/London/NY/Interbank)
with corner chart labels showing session phase + GW status
- InputParams.mqh: AI_Mode, AI_Gateway_URL, briefing TF flags,
AI_Session_Draw, Use_Watchlist_Gate
- GlobalVariables.mqh: gateway state, per-TF briefing cache,
session + news headlines globals
- MasterAICoordinator.mqh: wired to AIGateway (SetUseOpenAI shim kept)
- NewsEngine.mqh: merges live AI news bias from gateway
- AISignalConfirmation.mqh: delegates to AIValidateTrade()
- AILabels.mqh: GW status (color-coded), validation stats, per-TF briefs
- ChartLabels.mqh: session label integration
- profitgtx.mq5 v7.00: OnInit init gateway + session, OnTimer multi-TF
briefing refresh, OnTradeTransaction fire-and-forget trade report
- Recompile: 0 errors, 0 warnings
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-20 06:34:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CleanupSessionLabel()
|
|
|
|
|
{
|
|
|
|
|
ObjectDelete(0, "GW_SESSION_LABEL");
|
|
|
|
|
ObjectDelete(0, "GW_NEWS_LABEL");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|