forked from MasoodIqbal/RSI-Stoch-MA-EA
274 lines
No EOL
10 KiB
MQL5
274 lines
No EOL
10 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| QuarterTheory_VIZION_FINAL_v5.8_MODULAR.mq5 |
|
|
//| MODULAR VERSION: 15 files for maintainability |
|
|
//| PRAISE SYSTEM: 8 Trend Signals for Aggressive Continuation |
|
|
//| WARN vs PRAISE: Dynamic position sizing and setup priority |
|
|
//| War Survivor: 2.5x size + 25% MFIB partials | All 18 Active |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "QuarterTheory x VIZION"
|
|
#property version "5.80"
|
|
#property strict
|
|
|
|
//================ INCLUDE MQL5 LIBRARIES ==================//
|
|
#include <Trade/Trade.mqh>
|
|
CTrade Trade;
|
|
|
|
//================ INCLUDE MODULAR FILES ==================//
|
|
// Base configuration
|
|
#include "Config.mqh" // Enums & structures
|
|
#include "InputParams.mqh" // All input parameters
|
|
#include "GlobalVariables.mqh" // Global state
|
|
|
|
// Utilities
|
|
#include "Utilities.mqh" // Helper functions
|
|
|
|
// Core systems
|
|
#include "Indicators.mqh" // Indicator management
|
|
#include "FibLevels.mqh" // Fibonacci calculations
|
|
#include "Warnings.mqh" // Warning detection (17+ signals)
|
|
#include "Praise.mqh" // Praise signals (8 trend signals)
|
|
|
|
// Advanced systems
|
|
#include "MarketState.mqh" // Market mode detection
|
|
#include "ReEntry.mqh" // Re-entry combos (10 triggers)
|
|
#include "PositionManagement.mqh" // Position lifecycle
|
|
#include "TradeExecution.mqh" // Trade opening
|
|
#include "ChartLabels.mqh" // Visual feedback
|
|
#include "TradingSetups.mqh" // All 18 setups
|
|
#include "OpenAI.mqh" // OpenAI integration
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Expert initialization function |
|
|
//+------------------------------------------------------------------+
|
|
int OnInit()
|
|
{
|
|
Print("========================================");
|
|
Print("QuarterTheory_VIZION_FINAL v5.8 - MODULAR");
|
|
Print("⚔️ WAR SURVIVOR SYSTEM:");
|
|
Print(" - Aggressive MFIB Partials: 25% at each reject");
|
|
Print(" - Larger Initial Size: ", DoubleToString(War_Survivor_Lot_Multiplier, 1), "x multiplier");
|
|
Print(" - Max 4 MFIB partials per trade");
|
|
Print(" - Survive frequent trailing stops");
|
|
Print("🌟 PRAISE SYSTEM:");
|
|
Print(" - 8 trend strength signals");
|
|
Print(" - Dynamic sizing: Supreme (4+) = 2x, Strong (3) = 1.5x");
|
|
Print(" - Tighter trail (100pts) on supreme praise");
|
|
Print("🔁 SMART RE-ENTRY:");
|
|
Print(" - 10 combo triggers for post-SL/BE re-entry");
|
|
Print(" - 3+ Reject/Reclaim at MA140/230/500");
|
|
Print("📦 MODULAR ARCHITECTURE:");
|
|
Print(" - 15 separate files");
|
|
Print(" - Easy to maintain and extend");
|
|
Print("ALL 18 SETUPS ACTIVE:");
|
|
Print(" - 14 Continuation (150 SL, 4000 TP)");
|
|
Print(" - 4 Counter-Trend (50 SL, 3000 TP)");
|
|
Print("TRAILING SL:");
|
|
Print(" - Counter: 150pts behind price");
|
|
Print(" - Continuation: 300pts behind price");
|
|
Print(" - Supreme Praise: 100pts behind price");
|
|
|
|
if(Use_OpenAI)
|
|
{
|
|
Print("🤖 OPENAI INTEGRATION:");
|
|
Print(" - Model: ", OpenAI_Model_Choice);
|
|
Print(" - Trade Validation: ", AI_Validate_Trades ? "ENABLED" : "DISABLED");
|
|
Print(" - Daily Briefing: ", AI_Daily_Briefing ? "ENABLED" : "DISABLED");
|
|
}
|
|
|
|
Print("========================================");
|
|
|
|
// Initialize trade object
|
|
Trade.SetExpertMagicNumber(MagicNumber);
|
|
Trade.SetDeviationInPoints(50);
|
|
Trade.SetTypeFilling(ORDER_FILLING_FOK);
|
|
|
|
// Initialize indicators
|
|
if(!InitializeIndicators())
|
|
{
|
|
Print("❌ Failed to initialize indicators");
|
|
return INIT_FAILED;
|
|
}
|
|
|
|
// Initialize tracking arrays
|
|
ArrayInitialize(SetupCount, 0);
|
|
ArrayInitialize(LastEntryTime, 0);
|
|
|
|
// Calculate and draw levels
|
|
CalculateLevels();
|
|
if(Show_Levels)
|
|
DrawLevels();
|
|
|
|
// Initialize OpenAI (if enabled)
|
|
if(Use_OpenAI)
|
|
{
|
|
OpenAI_Model = OpenAI_Model_Choice;
|
|
AI_Initialized = InitializeOpenAI(OpenAI_API_Key);
|
|
|
|
if(!AI_Initialized)
|
|
{
|
|
Print("⚠️ OpenAI initialization failed - check API key");
|
|
Print("💡 Get API key from: https://platform.openai.com/api-keys");
|
|
}
|
|
else
|
|
{
|
|
Print("✅ OpenAI integration ready");
|
|
|
|
// Get initial market briefing
|
|
if(AI_Daily_Briefing)
|
|
{
|
|
Print("🤖 Fetching initial AI market analysis...");
|
|
string briefing = GetAIDailyBriefing();
|
|
DisplayAIBriefing(briefing);
|
|
}
|
|
}
|
|
}
|
|
|
|
Print("✅ Initialization complete");
|
|
return INIT_SUCCEEDED;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Expert deinitialization function |
|
|
//+------------------------------------------------------------------+
|
|
void OnDeinit(const int reason)
|
|
{
|
|
// Release indicators
|
|
ReleaseIndicators();
|
|
|
|
// Clean up chart objects
|
|
CleanupLevels();
|
|
CleanupLabels();
|
|
|
|
Print("========================================");
|
|
Print("QuarterTheory_VIZION_FINAL v5.8 - Session Complete");
|
|
Print("Final Stats:");
|
|
Print(" Total Trades: ", TodayTrades);
|
|
Print(" Buys: ", BuyTrades, " | Sells: ", SellTrades);
|
|
Print(" Reversed: ", ClosedByReversal);
|
|
Print("========================================");
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Expert tick function |
|
|
//+------------------------------------------------------------------+
|
|
void OnTick()
|
|
{
|
|
//==============================================================
|
|
// PHASE 1: UPDATE INDICATORS
|
|
//==============================================================
|
|
UpdateIndicators();
|
|
|
|
//==============================================================
|
|
// PHASE 2: DETECT SIGNALS
|
|
//==============================================================
|
|
DetectWarnings(); // 17+ warning signals
|
|
DetectPraiseSignals(); // 8 trend strength signals
|
|
|
|
//==============================================================
|
|
// PHASE 3: RECALCULATE LEVELS (Every 100 ticks)
|
|
//==============================================================
|
|
static int tick_count = 0;
|
|
tick_count++;
|
|
if(tick_count >= 100)
|
|
{
|
|
CalculateLevels();
|
|
if(Show_Levels)
|
|
DrawLevels();
|
|
tick_count = 0;
|
|
}
|
|
|
|
//==============================================================
|
|
// PHASE 4: UPDATE MARKET STATE
|
|
//==============================================================
|
|
UpdateModeAndState(); // Detect TRENDING/RANGING/CHOP
|
|
// Determine CONTINUATION/PULLBACK/REVERSAL
|
|
|
|
//==============================================================
|
|
// PHASE 5: MANAGE EXISTING POSITIONS
|
|
//==============================================================
|
|
ManagePositions(); // Partial TPs, MFIB partials, BE, trailing
|
|
|
|
//==============================================================
|
|
// PHASE 6: EXECUTE NEW SETUPS
|
|
//==============================================================
|
|
ExecuteContinuationSetups(); // 14 continuation setups
|
|
ExecuteRangeSetups(); // Range trading setups
|
|
ExecuteChopSetups(); // Mean reversion setups
|
|
|
|
//==============================================================
|
|
// PHASE 7: UPDATE VISUAL FEEDBACK
|
|
//==============================================================
|
|
UpdateLabels(); // Mode, State, Warning, Praise, Signal labels
|
|
|
|
//==============================================================
|
|
// PHASE 8: AI OPERATIONS (If enabled)
|
|
//==============================================================
|
|
if(Use_OpenAI && AI_Initialized)
|
|
{
|
|
// Daily briefing at specified hour
|
|
if(AI_Daily_Briefing)
|
|
{
|
|
datetime now = TimeCurrent();
|
|
MqlDateTime dt;
|
|
TimeToStruct(now, dt);
|
|
|
|
// Check if it's briefing time and we haven't done it today
|
|
if(dt.hour == AI_Briefing_Hour && now - Last_AI_Briefing_Time > 3600)
|
|
{
|
|
Print("🤖 Generating daily AI briefing...");
|
|
string briefing = GetAIDailyBriefing();
|
|
DisplayAIBriefing(briefing);
|
|
Last_AI_Briefing_Time = now;
|
|
}
|
|
}
|
|
|
|
// Periodic pattern recognition (every hour)
|
|
static datetime last_pattern_check = 0;
|
|
if(TimeCurrent() - last_pattern_check > 3600)
|
|
{
|
|
Print("🤖 Running AI pattern recognition...");
|
|
string patterns = IdentifyPatternsWithAI();
|
|
Last_AI_Analysis = "Pattern Analysis: " + patterns;
|
|
last_pattern_check = TimeCurrent();
|
|
}
|
|
}
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| End of Modular QuarterTheory Trading Bot |
|
|
//+------------------------------------------------------------------+
|
|
/*
|
|
MODULAR ARCHITECTURE SUMMARY:
|
|
=============================
|
|
|
|
1. Config.mqh - Base definitions (enums, structures)
|
|
2. InputParams.mqh - All input parameters
|
|
3. GlobalVariables.mqh - Global state management
|
|
4. Utilities.mqh - Helper functions
|
|
5. Indicators.mqh - Indicator initialization/updates
|
|
6. FibLevels.mqh - Fibonacci calculations
|
|
7. Warnings.mqh - 17+ warning signal detection
|
|
8. Praise.mqh - 8 trend strength signals
|
|
9. MarketState.mqh - Market mode detection
|
|
10. ReEntry.mqh - 10 combo re-entry system
|
|
11. PositionManagement.mqh - Complete position lifecycle
|
|
12. TradeExecution.mqh - Trade opening logic
|
|
13. ChartLabels.mqh - Visual feedback system
|
|
14. TradingSetups.mqh - All 18 trading setups
|
|
15. Main EA file (this file) - Orchestration
|
|
|
|
BENEFITS:
|
|
=========
|
|
✓ Maintainable - Each file has single responsibility
|
|
✓ Readable - Small, focused files
|
|
✓ Testable - Independent modules
|
|
✓ Scalable - Easy to extend
|
|
✓ Collaborative - Multiple developers can work in parallel
|
|
|
|
TOTAL CODE:
|
|
===========
|
|
~2,500 lines across 15 files
|
|
Original monolith: 1,175 lines in 1 file
|
|
|
|
The modular version is longer but MUCH more maintainable!
|
|
*/ |