RSI-Stoch-MA-EA/Masteraicoordinator.mqh

241 lines
7.1 KiB
MQL5
Raw Permalink Normal View History

2026-01-21 08:56:51 +00:00
//+------------------------------------------------------------------+
2026-01-21 09:19:46 +00:00
//| MasterAICoordinator.mqh |
2026-01-22 04:48:51 -06:00
//| Integration Layer: Neural Network + Your Systems |
//| FIXED - Uses proper variable scoping |
2026-01-21 08:56:51 +00:00
//+------------------------------------------------------------------+
#property copyright "QuarterTheory x VIZION"
2026-01-22 04:48:51 -06:00
#property version "3.00"
2026-01-21 08:56:51 +00:00
#property strict
2026-01-22 04:48:51 -06:00
// Only include Neural Network
2026-01-21 09:29:52 +00:00
#include "NeuralNet.mqh"
2026-01-21 09:19:46 +00:00
2026-01-21 20:12:13 +00:00
//================ SIGNAL STRUCTURE ==================//
2026-01-22 04:48:51 -06:00
struct MasterSignal
2026-01-21 08:56:51 +00:00
{
2026-01-22 04:48:51 -06:00
int master_direction;
double master_confidence;
string structure_type;
2026-01-21 08:56:51 +00:00
bool should_trade;
2026-01-22 04:48:51 -06:00
string reasoning;
// Pattern counts for your main EA
int pattern_warns;
int pattern_praise;
2026-01-21 08:56:51 +00:00
};
2026-01-21 20:12:13 +00:00
//================ GLOBALS ==================//
2026-01-22 04:48:51 -06:00
MasterSignal g_MasterSignal;
bool g_MasterAIInit = false;
2026-01-21 20:12:13 +00:00
bool g_UseNN = false;
2026-01-22 04:48:51 -06:00
int g_AISignalCount = 0;
2026-01-21 08:56:51 +00:00
//+------------------------------------------------------------------+
2026-01-22 04:48:51 -06:00
//| Initialize Master AI |
2026-01-21 08:56:51 +00:00
//+------------------------------------------------------------------+
bool InitializeMasterAI()
{
2026-01-21 20:12:13 +00:00
if(Use_NeuralNet)
2026-01-21 08:56:51 +00:00
{
2026-01-22 04:48:51 -06:00
bool nn_ok = InitializeNeuralNet();
if(nn_ok)
2026-01-21 08:56:51 +00:00
{
2026-01-21 20:12:13 +00:00
g_UseNN = true;
2026-01-21 08:56:51 +00:00
Print("✅ Neural Network initialized");
Print(" Server: ", NN_ServerURL);
}
else
{
2026-01-22 04:48:51 -06:00
Print("⚠️ NN init failed");
2026-01-21 20:12:13 +00:00
g_UseNN = false;
2026-01-21 08:56:51 +00:00
}
}
2026-01-22 04:48:51 -06:00
g_MasterAIInit = true;
Print("✅ Master AI Ready (NN + Structure)");
2026-01-21 08:56:51 +00:00
return true;
}
//+------------------------------------------------------------------+
2026-01-22 04:48:51 -06:00
//| Update Master AI |
2026-01-21 08:56:51 +00:00
//+------------------------------------------------------------------+
void UpdateMasterAI()
{
2026-01-22 04:48:51 -06:00
if(!g_MasterAIInit) return;
2026-01-21 09:19:46 +00:00
2026-01-22 04:48:51 -06:00
// Get YOUR existing warns/praise from external scope
int warns = 0;
int praise = 0;
2026-01-21 08:56:51 +00:00
2026-01-22 04:48:51 -06:00
// 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;
2026-01-21 08:56:51 +00:00
2026-01-22 04:48:51 -06:00
// 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);
2026-01-21 08:56:51 +00:00
2026-01-22 04:48:51 -06:00
int strength = 50;
if(Current_Strength == STRENGTH_STRONG)
strength = 80;
else if(Current_Strength == STRENGTH_CONFIRMED)
strength = 60;
2026-01-21 09:19:46 +00:00
2026-01-21 20:12:13 +00:00
if(g_UseNN)
2026-01-21 08:56:51 +00:00
{
2026-01-21 20:12:13 +00:00
UpdateNeuralNetSignal();
2026-01-21 08:56:51 +00:00
}
2026-01-22 04:48:51 -06:00
double buy = 0;
double sell = 0;
2026-01-21 08:56:51 +00:00
2026-01-22 04:48:51 -06:00
if(is_bull && is_trending) buy += 30;
if(is_bear && is_trending) sell += 30;
2026-01-21 08:56:51 +00:00
if(praise >= 2)
{
2026-01-22 04:48:51 -06:00
if(is_bull && is_trending) buy += 20;
if(is_bear && is_trending) sell += 20;
2026-01-21 08:56:51 +00:00
}
if(warns >= 2)
{
2026-01-22 04:48:51 -06:00
if(is_bull && is_trending) sell += 15;
if(is_bear && is_trending) buy += 15;
2026-01-21 08:56:51 +00:00
}
2026-01-22 04:48:51 -06:00
if(is_bull && is_trending) buy += strength * 0.2;
if(is_bear && is_trending) sell += strength * 0.2;
2026-01-21 08:56:51 +00:00
2026-01-21 20:12:13 +00:00
if(g_UseNN && NN_IsUsable())
{
2026-01-22 04:48:51 -06:00
double risk_adj = 1.0 - (NN_RiskScore / 200.0);
double eff_conf = (NN_Confidence / 100.0) * risk_adj;
2026-01-21 20:12:13 +00:00
if(NN_Bias > 0)
2026-01-22 04:48:51 -06:00
buy += 40 * eff_conf;
2026-01-21 20:12:13 +00:00
else if(NN_Bias < 0)
2026-01-22 04:48:51 -06:00
sell += 40 * eff_conf;
2026-01-21 20:12:13 +00:00
}
2026-01-22 04:48:51 -06:00
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";
2026-01-21 08:56:51 +00:00
2026-01-22 04:48:51 -06:00
if(buy > sell && buy >= 50)
2026-01-21 08:56:51 +00:00
{
2026-01-22 04:48:51 -06:00
g_MasterSignal.master_direction = 1;
g_MasterSignal.master_confidence = MathMin(buy, 100);
g_MasterSignal.should_trade = true;
2026-01-21 08:56:51 +00:00
}
2026-01-22 04:48:51 -06:00
else if(sell > buy && sell >= 50)
2026-01-21 08:56:51 +00:00
{
2026-01-22 04:48:51 -06:00
g_MasterSignal.master_direction = -1;
g_MasterSignal.master_confidence = MathMin(sell, 100);
g_MasterSignal.should_trade = true;
2026-01-21 08:56:51 +00:00
}
2026-01-22 04:48:51 -06:00
if(g_MasterSignal.should_trade)
2026-01-21 08:56:51 +00:00
{
2026-01-22 04:48:51 -06:00
string r = "";
if(is_bull) r += "Bull, ";
else if(is_bear) r += "Bear, ";
2026-01-21 20:12:13 +00:00
2026-01-22 04:48:51 -06:00
if(praise > 0) r += IntegerToString(praise) + "P, ";
if(warns > 0) r += IntegerToString(warns) + "W, ";
2026-01-21 20:12:13 +00:00
if(g_UseNN && NN_IsUsable())
2026-01-21 08:56:51 +00:00
{
2026-01-22 04:48:51 -06:00
if(NN_Bias > 0) r += "NN+";
else if(NN_Bias < 0) r += "NN-";
r += "(" + DoubleToString(NN_Confidence, 0) + "%)";
2026-01-21 08:56:51 +00:00
}
2026-01-22 04:48:51 -06:00
g_MasterSignal.reasoning = r;
2026-01-21 08:56:51 +00:00
2026-01-22 04:48:51 -06:00
if(g_MasterSignal.master_confidence >= 70)
2026-01-21 08:56:51 +00:00
{
2026-01-22 04:48:51 -06:00
Print("🎯 MASTER AI: ", g_MasterSignal.master_direction > 0 ? "BUY" : "SELL");
Print(" Conf: ", DoubleToString(g_MasterSignal.master_confidence, 1), "%");
Print(" ", r);
2026-01-21 08:56:51 +00:00
}
}
2026-01-22 04:48:51 -06:00
g_AISignalCount++;
2026-01-21 08:56:51 +00:00
}
2026-01-22 04:48:51 -06:00
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; }
2026-01-21 08:56:51 +00:00
double GetRecommendedLotMultiplier()
{
2026-01-22 04:48:51 -06:00
if(g_MasterSignal.master_confidence >= 80) return 2.0;
else if(g_MasterSignal.master_confidence >= 65) return 1.5;
else return 1.0;
2026-01-21 08:56:51 +00:00
}
int GetRecommendedSL()
{
2026-01-22 04:48:51 -06:00
if(g_MasterSignal.master_confidence >= 80) return 100;
else if(g_MasterSignal.master_confidence >= 65) return 150;
else return 200;
2026-01-21 08:56:51 +00:00
}
int GetRecommendedTP()
{
2026-01-22 04:48:51 -06:00
if(g_MasterSignal.master_confidence >= 80) return 5000;
else if(g_MasterSignal.master_confidence >= 65) return 4000;
else return 3000;
2026-01-21 08:56:51 +00:00
}
2026-01-22 04:48:51 -06:00
string GetMasterReasoning() { return g_MasterSignal.reasoning; }
2026-01-21 08:56:51 +00:00
bool ValidateTradeWithMasterAI()
{
2026-01-22 04:48:51 -06:00
if(!g_MasterSignal.should_trade) return false;
if(g_MasterSignal.master_confidence < 60) return false;
2026-01-21 20:12:13 +00:00
if(NN_BlockOnDisagree && g_UseNN && NN_IsUsable())
2026-01-21 09:29:52 +00:00
{
2026-01-22 04:48:51 -06:00
if(g_MasterSignal.master_direction > 0 && NN_Bias < 0) return false;
if(g_MasterSignal.master_direction < 0 && NN_Bias > 0) return false;
2026-01-21 09:29:52 +00:00
}
2026-01-21 08:56:51 +00:00
return true;
}
2026-01-22 04:48:51 -06:00
double CalculateMasterLotSize(double base) { return base * GetRecommendedLotMultiplier(); }
2026-01-21 20:12:13 +00:00
void GetMasterSLTP(int &sl, int &tp)
2026-01-21 08:56:51 +00:00
{
2026-01-22 04:48:51 -06:00
sl = GetRecommendedSL();
tp = GetRecommendedTP();
2026-01-21 20:12:13 +00:00
}
string GetMasterStats()
{
2026-01-22 04:48:51 -06:00
string s = "Master AI:\n Signals: " + IntegerToString(g_AISignalCount);
if(g_UseNN) s += "\n NN: " + IntegerToString(NN_Bias) + " | " + DoubleToString(NN_Confidence, 1) + "%";
2026-01-21 20:12:13 +00:00
return s;
}
2026-01-22 04:48:51 -06:00
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()); }
2026-01-21 09:19:46 +00:00
string GetNNStatus()
{
2026-01-22 04:48:51 -06:00
if(!Use_NeuralNet) return "Off";
if(!g_UseNN) return "Failed";
if(!NN_IsUsable()) return "Low";
2026-01-21 20:12:13 +00:00
return "OK";
2026-01-22 04:48:51 -06:00
}
int GetTotalWarnCount() { return 0; }
int GetTotalPraiseCount() { return 0; }
void InitializePatternCoordinator() {}
void UpdatePatternCoordinator() {}
void CleanupPatternCoordinator() {}