116 lines
5.4 KiB
MQL5
116 lines
5.4 KiB
MQL5
|
|
//+------------------------------------------------------------------+
|
||
|
|
//| AI EA PART 10.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 one 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
|
||
|
|
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
//| Global Variables |
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
//--- Store the OpenAI API key used to authenticate chat completion 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 chat panel rendering routines
|
||
|
|
#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 handlers
|
||
|
|
#include "AI Canvas Shell.mqh"
|
||
|
|
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
//| Expert initialization function |
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
int OnInit()
|
||
|
|
{
|
||
|
|
//--- Delegate initialization to the shell module and abort on failure
|
||
|
|
if(!Ai_Init())
|
||
|
|
return INIT_FAILED;
|
||
|
|
//--- Start the millisecond timer that drives the editor caret blink
|
||
|
|
EventSetMillisecondTimer(500);
|
||
|
|
//--- Report successful initialization
|
||
|
|
return INIT_SUCCEEDED;
|
||
|
|
}
|
||
|
|
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
//| Expert deinitialization function |
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
void OnDeinit(const int reason)
|
||
|
|
{
|
||
|
|
//--- Stop the millisecond timer
|
||
|
|
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 the chart event to the shell module for dispatch
|
||
|
|
Ai_OnChartEvent(id, lparam, dparam, sparam);
|
||
|
|
}
|
||
|
|
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
//| Timer function |
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
void OnTimer()
|
||
|
|
{
|
||
|
|
//--- Forward the timer tick to the shell module
|
||
|
|
Ai_OnTimer();
|
||
|
|
}
|
||
|
|
//+------------------------------------------------------------------+
|