mql5/Experts/Advisors/DualEA/Tests/Test_Integration.mq5

75 lines
2.6 KiB
MQL5
Raw Permalink Normal View History

2025-09-25 00:25:48 -04:00
//+------------------------------------------------------------------+
//| Test_Integration.mq5 |
//| Integration test: selector, gating, sizer, session, correlation |
//+------------------------------------------------------------------+
#include <Trade\Trade.mqh>
2026-02-05 23:31:20 -05:00
#include "..\\Include\\IStrategy.mqh"
2025-09-25 00:25:48 -04:00
#include "..\\Include\\GateManager.mqh"
#include "..\\Include\\SessionManager.mqh"
#include "..\\Include\\CorrelationManager.mqh"
#include "..\\Include\\VolatilitySizer.mqh"
#include "..\\Include\\LearningBridge.mqh"
2026-02-05 23:31:20 -05:00
#include "..\\Include\\StrategySelector.mqh"
2025-09-25 00:25:48 -04:00
input int Verbosity = 2;
void OnStart()
{
Print("[Test] Integration: BEGIN");
// Setup
CStrategySelector selector;
2026-02-05 23:31:20 -05:00
CLearningBridge *learning = new CLearningBridge("TestData", 100);
CGateManager gm(false, false, false);
2025-09-25 00:25:48 -04:00
CSessionManager sm(_Symbol, _Period);
CCorrelationManager cm(_Symbol, _Period);
CVolatilitySizer vs(_Symbol, _Period);
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 = "INT_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;
2025-09-25 00:25:48 -04:00
2026-02-05 23:31:20 -05:00
Print("PASS: TradingSignal created for integration test");
2025-09-25 00:25:48 -04:00
// Session check
2025-10-03 01:39:11 -04:00
string reason;
2025-09-25 00:25:48 -04:00
if(sm.IsSessionAllowed(reason)) Print("PASS: SessionManager allowed");
2026-02-05 23:31:20 -05:00
else PrintFormat("INFO: SessionManager blocked (%s)", reason);
2025-09-25 00:25:48 -04:00
// Correlation check
2025-10-03 01:39:11 -04:00
double corr = cm.GetCorrelation(_Symbol);
2025-09-25 00:25:48 -04:00
PrintFormat("INFO: CorrelationManager self-corr = %.2f", corr);
2026-02-05 23:31:20 -05:00
// Sizer test
2025-09-25 00:25:48 -04:00
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-09-25 00:25:48 -04:00
PrintFormat("INFO: VolatilitySizer sized = %.2f (%s)", sized, reason);
2026-02-05 23:31:20 -05:00
// Selector test
2025-09-25 00:25:48 -04:00
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-09-25 00:25:48 -04:00
Print("[Test] Integration: END");
}