| //+------------------------------------------------------------------+
|
| //| AI EA PART 13.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
|
|
|
| //--- Draw every brand mark and icon as vectors so the EA ships as a single crisp file
|
|
|
| //+------------------------------------------------------------------+
|
| //| 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
|
|
|
| input group "=== CONTEXT / TOOLS ==="
|
| input bool Enable_AI_Context = true; // Attach live market context
|
| input int Context_Candles = 15; // Context: recent closed candles to include
|
| input bool Enable_AI_Tools = false; // Let the AI call native data tools
|
| input int AI_Tool_Rounds = 4; // Tools: max tool-call rounds per message
|
|
|
| input group "=== AI TRADE ACTION SETTINGS ==="
|
| input bool Enable_AI_Actions = true; // Let the AI place and manage trades
|
| input bool Action_AutoApprove = false; // Execute AI actions without approval
|
| input double Action_MaxLots = 0.10; // Max lots per AI action
|
| input int Action_MaxPositions = 5; // Max open positions allowed for AI actions
|
| input bool Action_ChartSymbolOnly = true; // Restrict AI actions to the chart symbol
|
|
|
| //+------------------------------------------------------------------+
|
| //| 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 extern forward declarations and avoid type conflicts
|
| #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, carrying context, vision, tools and action code
|
| #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();
|
| }
|
| //+------------------------------------------------------------------+
|