Vizion-Trading-EA/AISession.mqh
Sahr John 4049f984ee 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

79 lines
2.5 KiB
MQL5

#ifndef AI_SESSION_MQH
#define AI_SESSION_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";
}
void InitAISession()
{
GW_Session_Name = GetCurrentSession();
GW_Session_Phase = "Unknown";
GW_Session_Confidence = 0.0;
}
void UpdateSessionLabel()
{
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;
string lbl = "GW_SESSION_LABEL";
if(ObjectFind(0, lbl) < 0)
ObjectCreate(0, lbl, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, lbl, OBJPROP_CORNER, CORNER_LEFT_LOWER);
ObjectSetInteger(0, lbl, OBJPROP_XDISTANCE, 10);
ObjectSetInteger(0, lbl, OBJPROP_YDISTANCE, 30);
ObjectSetInteger(0, lbl, OBJPROP_COLOR, clrSkyBlue);
ObjectSetInteger(0, lbl, OBJPROP_FONTSIZE, 9);
ObjectSetString( 0, lbl, OBJPROP_TEXT, text);
// News headline label (if any)
if(StringLen(GW_News_Headlines) > 0)
{
string nlbl = "GW_NEWS_LABEL";
if(ObjectFind(0, nlbl) < 0)
ObjectCreate(0, nlbl, OBJ_LABEL, 0, 0, 0);
string ntext = " News: " + StringSubstr(GW_News_Headlines, 0, 100);
ObjectSetInteger(0, nlbl, OBJPROP_CORNER, CORNER_LEFT_LOWER);
ObjectSetInteger(0, nlbl, OBJPROP_XDISTANCE, 10);
ObjectSetInteger(0, nlbl, OBJPROP_YDISTANCE, 48);
ObjectSetInteger(0, nlbl, OBJPROP_COLOR, clrKhaki);
ObjectSetInteger(0, nlbl, OBJPROP_FONTSIZE, 8);
ObjectSetString( 0, nlbl, OBJPROP_TEXT, ntext);
}
}
void CleanupSessionLabel()
{
ObjectDelete(0, "GW_SESSION_LABEL");
ObjectDelete(0, "GW_NEWS_LABEL");
}
#endif