//+------------------------------------------------------------------+ //| MasterAICoordinator.mqh | //| Integration Layer: Neural Network + Your Systems | //| FIXED - Uses proper variable scoping | //+------------------------------------------------------------------+ #property copyright "QuarterTheory x VIZION" #property version "3.00" #property strict // Only include Neural Network #include "NeuralNet.mqh" //================ SIGNAL STRUCTURE ==================// struct MasterSignal { int master_direction; double master_confidence; string structure_type; bool should_trade; string reasoning; // Pattern counts for your main EA int pattern_warns; int pattern_praise; }; //================ GLOBALS ==================// MasterSignal g_MasterSignal; bool g_MasterAIInit = false; bool g_UseNN = false; int g_AISignalCount = 0; //+------------------------------------------------------------------+ //| Initialize Master AI | //+------------------------------------------------------------------+ bool InitializeMasterAI() { if(Use_NeuralNet) { bool nn_ok = InitializeNeuralNet(); if(nn_ok) { g_UseNN = true; Print("โœ… Neural Network initialized"); Print(" Server: ", NN_ServerURL); } else { Print("โš ๏ธ NN init failed"); g_UseNN = false; } } g_MasterAIInit = true; Print("โœ… Master AI Ready (NN + Structure)"); return true; } //+------------------------------------------------------------------+ //| Update Master AI | //+------------------------------------------------------------------+ void UpdateMasterAI() { if(!g_MasterAIInit) return; // Get YOUR existing warns/praise from external scope int warns = 0; int praise = 0; // Try to access your globals (they're in GlobalVariables.mqh) // These are set by your DetectWarnings() and DetectPraiseSignals() warns = Warning_Confluence_Count; praise = Praise_Count; // Get YOUR market state bool is_bull = (Current_Bias == BIAS_BULL); bool is_bear = (Current_Bias == BIAS_BEAR); bool is_trending = (Current_Family == FAMILY_TRENDING); int strength = 50; if(Current_Strength == STRENGTH_STRONG) strength = 80; else if(Current_Strength == STRENGTH_CONFIRMED) strength = 60; if(g_UseNN) { UpdateNeuralNetSignal(); } double buy = 0; double sell = 0; if(is_bull && is_trending) buy += 30; if(is_bear && is_trending) sell += 30; if(praise >= 2) { if(is_bull && is_trending) buy += 20; if(is_bear && is_trending) sell += 20; } if(warns >= 2) { if(is_bull && is_trending) sell += 15; if(is_bear && is_trending) buy += 15; } if(is_bull && is_trending) buy += strength * 0.2; if(is_bear && is_trending) sell += strength * 0.2; if(g_UseNN && NN_IsUsable()) { double risk_adj = 1.0 - (NN_RiskScore / 200.0); double eff_conf = (NN_Confidence / 100.0) * risk_adj; if(NN_Bias > 0) buy += 40 * eff_conf; else if(NN_Bias < 0) sell += 40 * eff_conf; } g_MasterSignal.master_direction = 0; g_MasterSignal.master_confidence = 0; g_MasterSignal.should_trade = false; g_MasterSignal.pattern_warns = warns; g_MasterSignal.pattern_praise = praise; if(is_bull && is_trending) g_MasterSignal.structure_type = "Uptrend"; else if(is_bear && is_trending) g_MasterSignal.structure_type = "Downtrend"; else g_MasterSignal.structure_type = "Ranging"; if(buy > sell && buy >= 50) { g_MasterSignal.master_direction = 1; g_MasterSignal.master_confidence = MathMin(buy, 100); g_MasterSignal.should_trade = true; } else if(sell > buy && sell >= 50) { g_MasterSignal.master_direction = -1; g_MasterSignal.master_confidence = MathMin(sell, 100); g_MasterSignal.should_trade = true; } if(g_MasterSignal.should_trade) { string r = ""; if(is_bull) r += "Bull, "; else if(is_bear) r += "Bear, "; if(praise > 0) r += IntegerToString(praise) + "P, "; if(warns > 0) r += IntegerToString(warns) + "W, "; if(g_UseNN && NN_IsUsable()) { if(NN_Bias > 0) r += "NN+"; else if(NN_Bias < 0) r += "NN-"; r += "(" + DoubleToString(NN_Confidence, 0) + "%)"; } g_MasterSignal.reasoning = r; if(g_MasterSignal.master_confidence >= 70) { Print("๐ŸŽฏ MASTER AI: ", g_MasterSignal.master_direction > 0 ? "BUY" : "SELL"); Print(" Conf: ", DoubleToString(g_MasterSignal.master_confidence, 1), "%"); Print(" ", r); } } g_AISignalCount++; } MasterSignal GetMasterSignal() { return g_MasterSignal; } int GetMasterDirection() { return g_MasterSignal.master_direction; } double GetMasterConfidence() { return g_MasterSignal.master_confidence; } bool ShouldTakeMasterSignal() { return g_MasterSignal.should_trade; } double GetRecommendedLotMultiplier() { if(g_MasterSignal.master_confidence >= 80) return 2.0; else if(g_MasterSignal.master_confidence >= 65) return 1.5; else return 1.0; } int GetRecommendedSL() { if(g_MasterSignal.master_confidence >= 80) return 100; else if(g_MasterSignal.master_confidence >= 65) return 150; else return 200; } int GetRecommendedTP() { if(g_MasterSignal.master_confidence >= 80) return 5000; else if(g_MasterSignal.master_confidence >= 65) return 4000; else return 3000; } string GetMasterReasoning() { return g_MasterSignal.reasoning; } bool ValidateTradeWithMasterAI() { if(!g_MasterSignal.should_trade) return false; if(g_MasterSignal.master_confidence < 60) return false; if(NN_BlockOnDisagree && g_UseNN && NN_IsUsable()) { if(g_MasterSignal.master_direction > 0 && NN_Bias < 0) return false; if(g_MasterSignal.master_direction < 0 && NN_Bias > 0) return false; } return true; } double CalculateMasterLotSize(double base) { return base * GetRecommendedLotMultiplier(); } void GetMasterSLTP(int &sl, int &tp) { sl = GetRecommendedSL(); tp = GetRecommendedTP(); } string GetMasterStats() { string s = "Master AI:\n Signals: " + IntegerToString(g_AISignalCount); if(g_UseNN) s += "\n NN: " + IntegerToString(NN_Bias) + " | " + DoubleToString(NN_Confidence, 1) + "%"; return s; } void SetUseNeuralNetwork(bool use) { g_UseNN = use; } void SetUseOpenAI(bool use) {} void SetRequireAIValidation(bool require) {} void CleanupMasterAI() { Print("๐Ÿงน Master AI cleanup"); Print(GetMasterStats()); } bool IsNNHealthy() { return (g_UseNN && NN_IsUsable()); } string GetNNStatus() { if(!Use_NeuralNet) return "Off"; if(!g_UseNN) return "Failed"; if(!NN_IsUsable()) return "Low"; return "OK"; } int GetTotalWarnCount() { return 0; } int GetTotalPraiseCount() { return 0; } void InitializePatternCoordinator() {} void UpdatePatternCoordinator() {} void CleanupPatternCoordinator() {}