2025-10-03 01:39:11 -04:00
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Test_System.mq5 |
|
|
|
|
|
//| System-level E2E test: full pipeline, logging, export, errors |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
#include <Trade\Trade.mqh>
|
2026-02-05 23:31:20 -05:00
|
|
|
#include "..\\Include\\IStrategy.mqh"
|
2025-10-03 01:39:11 -04:00
|
|
|
#include "..\\Include\\GateManager.mqh"
|
|
|
|
|
#include "..\\Include\\SessionManager.mqh"
|
|
|
|
|
#include "..\\Include\\CorrelationManager.mqh"
|
|
|
|
|
#include "..\\Include\\VolatilitySizer.mqh"
|
|
|
|
|
#include "..\\Include\\LearningBridge.mqh"
|
|
|
|
|
#include "..\\Include\\KnowledgeBase.mqh"
|
|
|
|
|
#include "..\\Include\\PolicyEngine.mqh"
|
2026-02-05 23:31:20 -05:00
|
|
|
#include "..\\Include\\StrategySelector.mqh"
|
2025-10-03 01:39:11 -04:00
|
|
|
|
|
|
|
|
input int Verbosity = 2;
|
|
|
|
|
|
|
|
|
|
void OnStart()
|
|
|
|
|
{
|
|
|
|
|
Print("[Test] System: BEGIN");
|
|
|
|
|
// Full pipeline setup
|
|
|
|
|
CStrategySelector selector;
|
2026-02-05 23:31:20 -05:00
|
|
|
CLearningBridge *learning = new CLearningBridge("TestData", 100);
|
|
|
|
|
CGateManager gm(false, false, false);
|
2025-10-03 01:39:11 -04:00
|
|
|
CSessionManager sm(_Symbol, _Period);
|
|
|
|
|
CCorrelationManager cm(_Symbol, _Period);
|
|
|
|
|
CVolatilitySizer vs(_Symbol, _Period);
|
|
|
|
|
CKnowledgeBase kb;
|
|
|
|
|
CPolicyEngine policy;
|
|
|
|
|
|
|
|
|
|
sm.SetSessionHours(9, 17);
|
|
|
|
|
sm.SetMaxTradesPerSession(3);
|
|
|
|
|
cm.SetMaxCorrelation(0.8);
|
|
|
|
|
cm.SetLookbackDays(30);
|
|
|
|
|
vs.SetATRPeriod(14);
|
|
|
|
|
vs.SetBaseATRPercent(0.5);
|
|
|
|
|
vs.SetMultiplierRange(0.5, 2.0);
|
|
|
|
|
vs.SetTargetRiskPercent(1.0);
|
|
|
|
|
vs.SetEnabled(true);
|
|
|
|
|
|
2026-02-05 23:31:20 -05:00
|
|
|
// Simulate a signal using TradingSignal from IStrategy.mqh
|
2025-10-03 01:39:11 -04:00
|
|
|
TradingSignal signal;
|
2026-02-05 23:31:20 -05:00
|
|
|
signal.strategy_name = "SYS_TEST";
|
2025-10-03 01:39:11 -04:00
|
|
|
signal.symbol = _Symbol;
|
|
|
|
|
signal.timeframe = _Period;
|
|
|
|
|
signal.timestamp = TimeCurrent();
|
2026-02-05 23:31:20 -05:00
|
|
|
signal.entry_price = SymbolInfoDouble(_Symbol, SYMBOL_BID);
|
|
|
|
|
signal.direction = 1; // Buy
|
|
|
|
|
signal.stop_loss = signal.entry_price - 100 * _Point;
|
|
|
|
|
signal.take_profit = signal.entry_price + 200 * _Point;
|
2025-10-03 01:39:11 -04:00
|
|
|
signal.confidence = 0.75;
|
|
|
|
|
|
2026-02-05 23:31:20 -05:00
|
|
|
Print("PASS: TradingSignal created for system test");
|
2025-10-03 01:39:11 -04:00
|
|
|
|
|
|
|
|
string reason;
|
|
|
|
|
if(sm.IsSessionAllowed(reason)) Print("PASS: SessionManager allowed");
|
2026-02-05 23:31:20 -05:00
|
|
|
else PrintFormat("INFO: SessionManager blocked (%s)", reason);
|
2025-10-03 01:39:11 -04:00
|
|
|
|
|
|
|
|
double corr = cm.GetCorrelation(_Symbol);
|
|
|
|
|
PrintFormat("INFO: CorrelationManager self-corr = %.2f", corr);
|
|
|
|
|
|
|
|
|
|
double sl_points = 50, vol_mult = 1.0;
|
2026-02-05 23:31:20 -05:00
|
|
|
double sized = vs.CalculatePositionSize(0.1, sl_points, vol_mult, reason);
|
2025-10-03 01:39:11 -04:00
|
|
|
PrintFormat("INFO: VolatilitySizer sized = %.2f (%s)", sized, reason);
|
|
|
|
|
|
|
|
|
|
string strats[] = {"ADXStrategy", "RSIStrategy"};
|
|
|
|
|
double scores[];
|
|
|
|
|
int idx = selector.PickBest(_Symbol, _Period, strats, scores);
|
|
|
|
|
if(idx >= 0 && idx < ArraySize(strats))
|
|
|
|
|
PrintFormat("PASS: Selector picked %s", strats[idx]);
|
|
|
|
|
else
|
2026-02-05 23:31:20 -05:00
|
|
|
Print("INFO: Selector did not pick (normal for test)");
|
2025-10-03 01:39:11 -04:00
|
|
|
|
|
|
|
|
// Trade log
|
2026-02-05 23:31:20 -05:00
|
|
|
bool log_ok = kb.LogTradeExecution(_Symbol, signal.strategy_name, TimeCurrent(), signal.entry_price, 0.1, signal.direction);
|
2025-10-03 01:39:11 -04:00
|
|
|
if(log_ok) Print("PASS: KnowledgeBase trade log");
|
2026-02-05 23:31:20 -05:00
|
|
|
else Print("INFO: KnowledgeBase trade log (may require setup)");
|
2025-10-03 01:39:11 -04:00
|
|
|
|
|
|
|
|
// Policy engine (smoke)
|
|
|
|
|
double prob = policy.GetPolicyProb("ADXStrategy", _Symbol, _Period);
|
|
|
|
|
PrintFormat("INFO: PolicyEngine GetPolicyProb = %.4f", prob);
|
|
|
|
|
|
2026-02-24 12:48:15 -05:00
|
|
|
if(learning != NULL)
|
|
|
|
|
{
|
|
|
|
|
delete learning;
|
|
|
|
|
learning = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-03 01:39:11 -04:00
|
|
|
Print("[Test] System: END");
|
|
|
|
|
}
|