mql5/Experts/Advisors/DualEA/Examples/UnifiedSystemExample.mq5

124 lines
4.4 KiB
MQL5
Raw Permalink Normal View History

2025-10-03 01:38:28 -04:00
//+------------------------------------------------------------------+
//| UnifiedSystemExample.mq5 - Example of Unified DualEA System |
//+------------------------------------------------------------------+
#property copyright "DualEA Team"
#property link ""
#property version "1.00"
2026-02-05 23:31:20 -05:00
// New Architecture: Auto-learning gate system
#include "../Include/GateSystemAutoLearning.mqh"
2025-10-03 01:38:28 -04:00
#include "../Include/ConfigManager.mqh"
#include "../Include/EventBus.mqh"
2026-02-05 23:31:20 -05:00
#include "../Include/CSystemMonitor.mqh"
#include "../Include/LearningBridge.mqh"
2025-10-03 01:38:28 -04:00
// Input parameters
input bool UnifiedMode = true; // Enable unified system
input bool VerboseLogging = false; // Enable verbose logging
input bool NoConstraintsMode = false; // Disable all constraints for testing
input int MonitoringInterval = 60; // System monitoring interval (seconds)
2026-02-05 23:31:20 -05:00
// Global objects - Use new CEfficientGateManagerEnhanced type
CEfficientGateManagerEnhanced *g_gate_manager = NULL;
2025-10-03 01:38:28 -04:00
CLearningBridge *g_learning = NULL;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
Print("=== Initializing Unified DualEA System Example ===");
// Initialize learning bridge
2026-02-05 23:31:20 -05:00
g_learning = new CLearningBridge("DualEA_Example", 1000);
2025-10-03 01:38:28 -04:00
2026-02-05 23:31:20 -05:00
// Initialize gate manager
g_gate_manager = new CEfficientGateManagerEnhanced(NoConstraintsMode, UnifiedMode, false);
2025-10-03 01:38:28 -04:00
// Set up timer for monitoring
EventSetTimer(MonitoringInterval);
Print("=== DualEA Example EA Initialized Successfully ===");
return INIT_SUCCEEDED;
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Print("=== Shutting Down DualEA Example EA ===");
EventKillTimer();
// Clean up objects
if(g_gate_manager != NULL)
{
delete g_gate_manager;
g_gate_manager = NULL;
}
if(g_learning != NULL)
{
delete g_learning;
g_learning = NULL;
}
Print("DualEA Example EA shutdown complete");
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
static datetime last_signal_time = 0;
static int signal_counter = 0;
// Generate example signals every 10 ticks (for demonstration)
static int tick_counter = 0;
tick_counter++;
if(tick_counter % 10 == 0 && TimeCurrent() - last_signal_time > 30)
{
2026-02-05 23:31:20 -05:00
// Create example trading signal using TradingSignal from IStrategy.mqh
2025-10-03 01:38:28 -04:00
TradingSignal signal;
2026-02-05 23:31:20 -05:00
signal.strategy_name = "EXAMPLE_" + IntegerToString(signal_counter++);
2025-10-03 01:38:28 -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 = (signal_counter % 2 == 0) ? 1 : -1; // Alternate buy/sell
signal.stop_loss = signal.entry_price - (signal.direction == 1 ? 100 : -100) * _Point;
signal.take_profit = signal.entry_price + (signal.direction == 1 ? 200 : -200) * _Point;
2025-10-03 01:38:28 -04:00
signal.confidence = 0.6 + (MathRand() % 40) / 100.0; // Random confidence 0.6-1.0
2026-02-05 23:31:20 -05:00
Print("Signal ", signal.strategy_name, " generated - Direction: ",
signal.direction == 1 ? "BUY" : "SELL",
" Price: ", DoubleToString(signal.entry_price, Digits()));
2025-10-03 01:38:28 -04:00
last_signal_time = TimeCurrent();
}
}
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
static int timer_counter = 0;
timer_counter++;
if(timer_counter % 5 == 0) // Every 5 timer intervals
{
Print("\n=== System Status Update ===");
2026-02-05 23:31:20 -05:00
// Check system health
CSystemMonitor monitor;
double health_score = monitor.CalculateHealthScore();
double cpu_percent = 0.0;
double memory_used_mb = 0.0;
Print(StringFormat("Health Score: %.1f | CPU: %.1f%% | Memory: %.1f MB",
health_score, cpu_percent, memory_used_mb));
2025-10-03 01:38:28 -04:00
}
}