//+------------------------------------------------------------------+ //| AI ChatGPT EA Part 9.mq5 | //| Copyright 2026, Allan Munene Mutiiria. | //| https://t.me/Forex_Algo_Trader | //+------------------------------------------------------------------+ #property copyright "Copyright 2026, Allan Munene Mutiiria." #property link "https://t.me/Forex_Algo_Trader" #property version "1.00" #property strict #property icon "1. Forex Algo-Trader.ico" //--- Embed bitmap resources used by the AI chat shell interface #resource "AI MQL5.bmp" #resource "AI LOGO.bmp" #resource "AI NEW CHAT.bmp" #resource "AI CLEAR.bmp" #resource "AI HISTORY.bmp" #resource "AI SEARCH.bmp" //+------------------------------------------------------------------+ //| Inputs | //+------------------------------------------------------------------+ input group "=== OPENAI API SETTINGS ===" input string OpenAI_Model = "gpt-4o"; // OpenAI Model Name input string OpenAI_Endpoint = "https://api.openai.com/v1/chat/completions"; // OpenAI API Endpoint URL input int MaxResponseLength = 3000; // Max Response Length (Tokens) input group "=== LOGGING SETTINGS ===" input string LogFileName = "ChatGPT_EA_Log.txt"; // Log File Name input int MaxChartBars = 10; // Max Chart Bars To Send To AI input bool DeleteLogsOnChatDelete = true; // Clear Logs When Deleting Chats input group "=== AUTO-TRADING SETTINGS ===" input bool AutoTrade = true; // Enable Auto-Trading On AI Signals input double LotSize = 0.01; // Lot Size For Auto-Trades input int MagicNumber = 12345; // Magic Number For Trades input bool EnableAutoSignal = false; // Enable Auto Signal Check On New Bar //+------------------------------------------------------------------+ //| Global Variables | //+------------------------------------------------------------------+ //--- Hold the OpenAI API key used for authenticating chat requests string OpenAI_API_Key = "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"; //+------------------------------------------------------------------+ //| Module Includes | //+------------------------------------------------------------------+ //--- Define sentinel so headers skip their extern forward declarations //--- This prevents type conflicts between input-vs-extern of the same names //--- Standalone compilation of any .mqh leaves this undefined so externs emit #define AI_COMPILED_FROM_MAIN //--- Include theme constants and color definitions #include "AI Canvas Theme.mqh" //--- Include low-level canvas drawing primitives #include "AI Canvas Primitives.mqh" //--- Include JSON parsing and file utilities #include "AI JSON FILE.mqh" //--- Include shared canvas state structures and globals #include "AI Canvas State.mqh" //--- Include scrollbar component logic #include "AI Canvas Scrollbar.mqh" //--- Include text editor and caret handling #include "AI Canvas Editor.mqh" //--- Include rendering routines for the chat panel #include "AI Canvas Render.mqh" //--- Include trading and AI signal logic #include "AI Logic.mqh" //--- Include user interaction and input dispatch #include "AI Canvas Interact.mqh" //--- Include top-level shell lifecycle (init, deinit, tick, events) #include "AI Canvas Shell.mqh" //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- Delegate initialization to the shell module if(!Ai_Init()) return INIT_FAILED; //--- Start the millisecond timer for editor caret blink EventSetMillisecondTimer(500); //--- Report successful initialization return INIT_SUCCEEDED; } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- Stop the timer event EventKillTimer(); //--- Delegate cleanup to the shell module Ai_Deinit(); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- Forward tick handling to the shell module Ai_OnTick(); } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- Forward chart event to the shell module for dispatch Ai_OnChartEvent(id, lparam, dparam, sparam); } //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ void OnTimer() { //--- Forward timer tick to the shell module Ai_OnTimer(); } //+------------------------------------------------------------------+