165 lines
3.8 KiB
MQL5
165 lines
3.8 KiB
MQL5
|
|
//+------------------------------------------------------------------+
|
||
|
|
//| profitgtx.mq5 |
|
||
|
|
//| Trading EA entrypoint (profitgtx) |
|
||
|
|
//| Base: AlgoForge RSI-Stoch-MA-EA modular v5.8 |
|
||
|
|
//| Extensions: News bias, SignalCoordinator, NN logging, OpenAI gate|
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
#property copyright "QuarterTheory x VIZION"
|
||
|
|
#property version "6.00"
|
||
|
|
#property strict
|
||
|
|
|
||
|
|
#include <Trade/Trade.mqh>
|
||
|
|
CTrade Trade;
|
||
|
|
|
||
|
|
// Base configuration
|
||
|
|
#include "Config.mqh"
|
||
|
|
#include "InputParams.mqh"
|
||
|
|
#include "GlobalVariables.mqh"
|
||
|
|
|
||
|
|
// Utilities + core systems
|
||
|
|
#include "Utilities.mqh"
|
||
|
|
#include "Indicators.mqh"
|
||
|
|
#include "FibLevels.mqh"
|
||
|
|
#include "Warnings.mqh"
|
||
|
|
#include "Praise.mqh"
|
||
|
|
#include "PatternCoordinator.mqh"
|
||
|
|
|
||
|
|
// Advanced systems
|
||
|
|
#include "MarketState.mqh"
|
||
|
|
#include "ReEntry.mqh"
|
||
|
|
#include "PositionManagement.mqh"
|
||
|
|
#include "TradeExecution.mqh"
|
||
|
|
#include "SignalCoordinator.mqh"
|
||
|
|
#include "NewsEngine.mqh"
|
||
|
|
#include "ChartLabels.mqh"
|
||
|
|
#include "TradingSetups.mqh"
|
||
|
|
|
||
|
|
// AI systems
|
||
|
|
#include "OpenAI.mqh"
|
||
|
|
#include "AISignalConfirmation.mqh"
|
||
|
|
#include "MasterAICoordinator.mqh"
|
||
|
|
|
||
|
|
// Reads API key from MQL5/Files/openai_api_key.txt if the input param is empty.
|
||
|
|
string LoadApiKey(const string input_key)
|
||
|
|
{
|
||
|
|
if(StringLen(input_key) >= 20) return input_key;
|
||
|
|
int fh = FileOpen("openai_api_key.txt", FILE_READ | FILE_TXT | FILE_ANSI);
|
||
|
|
if(fh == INVALID_HANDLE) return input_key;
|
||
|
|
string key = FileReadString(fh);
|
||
|
|
FileClose(fh);
|
||
|
|
StringTrimRight(key);
|
||
|
|
return key;
|
||
|
|
}
|
||
|
|
|
||
|
|
int OnInit()
|
||
|
|
{
|
||
|
|
// Trade object config
|
||
|
|
Trade.SetExpertMagicNumber(MagicNumber);
|
||
|
|
Trade.SetDeviationInPoints(50);
|
||
|
|
Trade.SetTypeFilling(ORDER_FILLING_FOK);
|
||
|
|
|
||
|
|
if(!InitializeIndicators())
|
||
|
|
return INIT_FAILED;
|
||
|
|
|
||
|
|
ArrayInitialize(SetupCount, 0);
|
||
|
|
ArrayInitialize(LastEntryTime, 0);
|
||
|
|
|
||
|
|
InitializeSignalCoordinator();
|
||
|
|
ApplySymbolProfile();
|
||
|
|
InitReEntry();
|
||
|
|
InitNewsEngine();
|
||
|
|
UpdateNewsEngine();
|
||
|
|
|
||
|
|
CalculateLevels();
|
||
|
|
if(Show_Levels) DrawLevels();
|
||
|
|
|
||
|
|
// OpenAI is mandatory: fail closed.
|
||
|
|
string resolved_key = LoadApiKey(OpenAI_API_Key);
|
||
|
|
if(StringLen(resolved_key) < 20)
|
||
|
|
return INIT_FAILED;
|
||
|
|
|
||
|
|
OpenAI_Model = OpenAI_Model_Choice;
|
||
|
|
AI_Initialized = InitializeOpenAI(resolved_key);
|
||
|
|
if(!AI_Initialized)
|
||
|
|
return INIT_FAILED;
|
||
|
|
|
||
|
|
if(AI_Daily_Briefing)
|
||
|
|
{
|
||
|
|
string briefing = GetAIDailyBriefing();
|
||
|
|
DisplayAIBriefing(briefing);
|
||
|
|
}
|
||
|
|
|
||
|
|
if(!InitializeMasterAI())
|
||
|
|
{
|
||
|
|
// Bot still runs, but without master AI enhancements.
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
SetUseNeuralNetwork(true);
|
||
|
|
SetUseOpenAI(true);
|
||
|
|
SetRequireAIValidation(true);
|
||
|
|
}
|
||
|
|
|
||
|
|
EventSetTimer(MathMax(5, News_Update_Seconds));
|
||
|
|
return INIT_SUCCEEDED;
|
||
|
|
}
|
||
|
|
|
||
|
|
void OnDeinit(const int reason)
|
||
|
|
{
|
||
|
|
EventKillTimer();
|
||
|
|
ReleaseIndicators();
|
||
|
|
CleanupLevels();
|
||
|
|
CleanupLabels();
|
||
|
|
CleanupMasterAI();
|
||
|
|
}
|
||
|
|
|
||
|
|
void OnTimer()
|
||
|
|
{
|
||
|
|
UpdateNewsEngine();
|
||
|
|
|
||
|
|
if(AI_Initialized && AI_Daily_Briefing)
|
||
|
|
{
|
||
|
|
datetime now = TimeCurrent();
|
||
|
|
MqlDateTime dt;
|
||
|
|
TimeToStruct(now, dt);
|
||
|
|
if(dt.hour == AI_Briefing_Hour && now - Last_AI_Briefing_Time > 3600)
|
||
|
|
{
|
||
|
|
string briefing = GetAIDailyBriefing();
|
||
|
|
DisplayAIBriefing(briefing);
|
||
|
|
Last_AI_Briefing_Time = now;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void OnTick()
|
||
|
|
{
|
||
|
|
UpdateIndicators();
|
||
|
|
UpdateMasterAI();
|
||
|
|
|
||
|
|
DetectWarnings();
|
||
|
|
DetectPraiseSignals();
|
||
|
|
|
||
|
|
static int tick_count = 0;
|
||
|
|
tick_count++;
|
||
|
|
if(tick_count >= 100)
|
||
|
|
{
|
||
|
|
CalculateLevels();
|
||
|
|
if(Show_Levels) DrawLevels();
|
||
|
|
tick_count = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
UpdateModeAndState();
|
||
|
|
CoordinateAllSignals();
|
||
|
|
|
||
|
|
ManagePositions();
|
||
|
|
|
||
|
|
ExecuteReEntries();
|
||
|
|
ExecuteMARetestAndRejectionSetups();
|
||
|
|
ExecuteContinuationSetups();
|
||
|
|
ExecuteRangeSetups();
|
||
|
|
ExecuteChopSetups();
|
||
|
|
ExecuteForceEntrySetups();
|
||
|
|
|
||
|
|
UpdateLabels();
|
||
|
|
}
|
||
|
|
|