This repository contains a collection of MQL5 libraries designed to integrate AI providers into expert advisors (EAs) for MetaTrader 5. It provides a structured framework for managing AI models, handling API connections, and executing trades based on AI-driven decisions.
- GitHub: https://github.com/aeitroc/
The library is organized into two main directories: Core and Utils, each containing specialized modules to handle different aspects of the AI integration.
The Core directory contains the essential components for managing AI providers, models, and decision-making processes.
AIProviderManager.mqh: Manages multiple AI providers, allowing for dynamic switching and fallback.APIKeyManager.mqh: Securely stores and retrieves API keys for different AI services.ConnectionMonitor.mqh: Monitors the connection status to AI providers and handles interruptions.DashboardManager.mqh: Provides a user interface for monitoring AI activity and performance.DecisionParser.mqh: Parses the raw output from AI models into structured trading decisions.DecisionValidator.mqh: Validates the trading decisions generated by the AI to ensure they meet predefined criteria.EmergencyStopSystem.mqh: Implements a fail-safe mechanism to halt trading in case of critical errors.ErrorHandler.mqh: Provides a centralized system for handling and logging errors.FallbackManager.mqh: Manages fallback to alternative AI models or providers in case of failure.ModelLoader.mqh: Loads and initializes AI models for use in the EA.ModelSelector.mqh: Selects the most appropriate AI model based on market conditions or other criteria.MultiModelAIManager.mqh: Manages multiple AI models simultaneously, allowing for ensemble strategies.PromptEngineer.mqh: Constructs and optimizes prompts sent to the AI models.RetryManager.mqh: Handles retries for failed API requests with exponential backoff.TradeExecutor.mqh: Executes trades based on the validated decisions from the AI.
The Utils directory contains helper modules that provide additional functionality to support the core components.
Logger.mqh: A simple utility for logging messages to the experts log.MarketDataCollector.mqh: Collects and preprocesses market data to be used as input for the AI models.RiskManager.mqh: Implements risk management rules, such as position sizing and stop-loss calculation.TradeManager.mqh: A comprehensive trade management utility for handling orders and positions.TradingHours.mqh: Defines and manages trading hours for different symbols.
To use these libraries in your MQL5 expert advisor, you need to include the main header file and initialize the core components.
#include <Core/AIProviderManager.mqh>
#include <Core/TradeExecutor.mqh>
#include <Utils/MarketDataCollector.mqh>
// Initialize core components
CMarketDataCollector* collector = new CMarketDataCollector();
CAIProviderManager* aiManager = new CAIProviderManager();
CTradeExecutor* executor = new CTradeExecutor();
// In your OnTick() function
void OnTick()
{
// Collect market data
string marketData = collector.GetMarketData(_Symbol);
// Get a trading decision from the AI
string decision = aiManager.GetDecision(marketData);
// Execute the trade
executor.Execute(decision);
}Trading foreign exchange on margin carries a high level of risk and may not be suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to trade foreign exchange, you should carefully consider your investment objectives, level of experience, and risk appetite.