// v7.29 (2026-11-09) setup conditions from the setup review: no entry against the H1 EMA20 slope; MAGNET-WALK-UP / FIB-BREAK-UP small against the H1 trend; small size in quiet markets (except MAGNET-WALK-DN)
// v7.27 (2026-11-09) weekly ladder: the leader scores the 20 ladder symbols hourly (research_scores); first sync/research 10 min after start
// v7.26 (2026-11-09) trade reports carry the account; the rotation leader re-sends 48h of closed positions every 30 min (broker values)
// v7.25 (2026-11-09) R-based exits: break-even at +1.5R, trail 1.5R from +2R, target unchanged (exit study: early BE/trail at +0.67R gave away ~70% of the edge)
// v7.24 (2026-11-09) rotation closes only charts it opened itself; hand-opened charts are never closed
// v7.23 (2026-11-09) watchlist rotation: 20-symbol watchlist, the ranker's top 10 trade; the leader chart opens and
// closes EA charts; new symbols trade at 0.25 size until they have 20 trades; Trade_Symbols -> Trade_Symbols_Fixed ("")
// v7.22 (2026-11-09) daily loss limit = 5% of start-of-day balance (was a flat 100), latched for the rest of the
// server day; coordinator logs "no signals" instead of "conflict 100" for an empty cluster
// v7.21 (2026-11-09) a chart that started while the AI gateway was down retries it every minute
// (it used to stay offline until reloaded and, with AI_Strict_Gate, refuse every trade)
// v7.20 (2026-11-09) learning upgrades - setups are upgraded from their record, never removed:
// - re-entries arm only after a winning / break-even parent (after a win: 71 re-entries 87% won +4,492;
// after a loss: 80 re-entries 4% won -7,947, 2026-10-09..11-06)
// - same-side stacking cap and no adding to a losing side (2026-11-06: 12 XAUUSD SELLs from 4 setups
// stacked into one rally, about -5,800)
// - daily loss limit counts open losses too
// - CHOP-SNAP moves from the blocklist to probation (trades at reduced size while it rebuilds a record)
#propertystrict
#include<Trade/Trade.mqh>
CTradeTrade;
// Base configuration
#include"Config.mqh"
#include"InputParams.mqh"
#include"GlobalVariables.mqh"
// Utilities + core systems
#include"Utilities.mqh"
#include"Indicators.mqh"
#include"RiskGuards.mqh"
#include"RiskSizing.mqh"
#include"FibLevels.mqh"
#include"TradePolicy.mqh"
#include"Warnings.mqh"
#include"Praise.mqh"
#include"PatternCoordinator.mqh"
// Advanced systems
#include"MATheory.mqh"
#include"MarketState.mqh"
#include"ReEntry.mqh"
#include"PositionManagement.mqh"
#include"TradeExecution.mqh"
#include"SignalCoordinator.mqh"
#include"NewsEngine.mqh"
#include"ChartLabels.mqh"
#include"TradingSetups.mqh"
// AI systems
#include"AISignalConfirmation.mqh"
#include"MasterAICoordinator.mqh"
#include"TradeSync.mqh"
#include"LadderResearch.mqh"
#include"Rotation.mqh"
intOnInit()
{
// Trade object config
Trade.SetExpertMagicNumber(MagicNumber);
Trade.SetDeviationInPoints(50);
Trade.SetTypeFilling(ORDER_FILLING_FOK);
if(!InitializeIndicators())
returnINIT_FAILED;
MAT_Init();
ArrayInitialize(SetupCount,0);
ArrayInitialize(LastEntryTime,0);
InitializeSignalCoordinator();
PanelInit();// restores a dragged panel position, if any
ApplySymbolProfile();
InitReEntry();
InitNewsEngine();
UpdateNewsEngine();
CalculateLevels();
if(Show_Levels)DrawLevels();
// Resolve live URLs (AUTO probes internal NN; LAPTOP/CONTAINER use fixed set)
// Must run before InitializeAIGateway() which uses g_gw_url
AutoDetectDeployment();
// AI Gateway (advisory: EA starts even if gateway is unreachable)
boolgw_ok=InitializeAIGateway();
if(!gw_ok)
returnINIT_FAILED;// Only fails when AI_Mode="mandatory" and gateway is down
InitAISession();
if(!InitializeMasterAI())
{
// Master AI unavailable — EA runs with NN + pattern system only
}
else
{
SetUseNeuralNetwork(true);
SetUseAIGateway(AI_Mode!="off");
SetRequireAIValidation(AI_Mode=="mandatory");
}
// Fetch initial D1 briefing if gateway is active
if(GW_Initialized&&AI_Briefing_D1)
{
GW_Brief_D1=AIFetchBriefing("D1");
if(StringLen(GW_Brief_D1)>0)
DisplayAIBriefing(GW_Brief_D1);
Last_GW_Briefing_D1=TimeCurrent();
}
EventSetTimer(MathMax(5,News_Update_Seconds));
returnINIT_SUCCEEDED;
}
voidOnDeinit(constintreason)
{
EventKillTimer();
MAT_Release();
ReleaseIndicators();
CleanupLevels();
CleanupLabels();
CleanupMasterAI();
}
// Chart snapshot for remote review (2026-09-17): MQL5\Filesizion\chart_<symbol>_<tf>.png