//+------------------------------------------------------------------+ //| PME_Validation_Test.mq5 | //| Quick Validation Test for PME Fixes | //+------------------------------------------------------------------+ #property script_show_inputs #include "Modules_PME/DataTypes_PME.mqh" #include "Modules_PME/Utilities_PME.mqh" #include "Modules_PME/RiskManager_PME.mqh" #include "Modules_PME/TechnicalAnalysis_PME_Merged.mqh" #include "Modules_PME/PositionManager_PME_Complete.mqh" //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { Print("\n========================================"); Print(" PME FIX VALIDATION TEST"); Print("========================================"); bool all_tests_passed = true; // Test 1: Module Initialization Print("\n[TEST 1] Module Initialization..."); CUtilities* utils = new CUtilities(); CRiskManager* risk = new CRiskManager(); CTechnicalAnalysis* tech = new CTechnicalAnalysis(); CPositionManager* manager = new CPositionManager(); if(utils == NULL || risk == NULL || tech == NULL || manager == NULL) { Print(" ❌ FAILED: Could not create modules"); all_tests_passed = false; } else { // Initialize modules bool init_ok = true; init_ok &= utils.Initialize(LOG_INFO, false); init_ok &= risk.Initialize(utils, 3.0, 10.0, 25.0); // New tolerances init_ok &= tech.Initialize(utils); init_ok &= manager.Initialize(utils, risk, tech, 0); if(init_ok) { Print(" ✅ PASSED: All modules initialized"); } else { Print(" ❌ FAILED: Module initialization failed"); all_tests_passed = false; } } // Test 2: Exit Behavior Configuration Print("\n[TEST 2] Exit Behavior Configuration..."); if(manager != NULL) { // Test if SetExitBehavior method exists (only in optimized version) manager.SetExitBehavior(true, 10, 100); Print(" ✅ PASSED: SetExitBehavior configured"); } // Test 3: Check Position Detection Print("\n[TEST 3] Position Detection..."); manager.ScanForPositions(); int count = manager.GetManagedCount(); Print(" ℹ️ Positions detected: ", count); // Test 4: Technical Analysis Thresholds Print("\n[TEST 4] Technical Analysis Settings..."); if(_Symbol != "") { double rsi = tech.GetRSI(_Symbol); Print(" Current RSI: ", DoubleToString(rsi, 1)); // Check if exit would trigger with old logic if(rsi > 70 && rsi <= 80) { Print(" ✅ RSI between 70-80: Old logic would exit, new won't"); } else if(rsi > 80) { Print(" ⚠️ RSI > 80: Would trigger exit in new logic too"); } else { Print(" ✅ RSI < 70: No exit signal"); } } // Test 5: Configuration Validation Print("\n[TEST 5] Configuration Check..."); ManagementConfig config; config.breakeven_trigger = 30; // Should be 30+ (was 20) config.trail_start = 50; // Should be 50+ (was 30) config.partial_trigger_1 = 50; // Should be 50+ (was 30) config.max_bars_in_trade = 500; // Should be 500+ (was 100) config.time_based_mgmt = false; // Should be false manager.SetConfiguration(config); Print(" ✅ PASSED: Conservative configuration set"); Print(" - Breakeven: 30 pts (was 20)"); Print(" - Trail: 50 pts (was 30)"); Print(" - Partial: 50 pts (was 30)"); Print(" - Max bars: 500 (was 100)"); Print(" - Time exits: DISABLED"); // Test 6: Position Management Simulation Print("\n[TEST 6] Management Logic Test..."); if(count > 0) { // Get first position ulong ticket = PositionGetTicket(0); if(PositionSelectByTicket(ticket)) { datetime open_time = (datetime)PositionGetInteger(POSITION_TIME); int bars = Bars(_Symbol, PERIOD_CURRENT, open_time, TimeCurrent()); Print(" Position #", ticket, " bars: ", bars); if(bars < 10) { Print(" ✅ Position has < 10 bars - should NOT exit"); } else { Print(" ℹ️ Position has ", bars, " bars - exits allowed"); } // Simulate management bool managed = manager.ManagePosition(ticket); if(managed) { Print(" ✅ Position managed successfully"); } } } else { Print(" ℹ️ No positions to test"); } // Test 7: Exit Signal Requirements Print("\n[TEST 7] Exit Signal Requirements..."); if(_Symbol != "") { // Create dummy position data ENUM_ORDER_TYPE type = ORDER_TYPE_BUY; double entry = SymbolInfoDouble(_Symbol, SYMBOL_BID) - 50 * _Point; double current = SymbolInfoDouble(_Symbol, SYMBOL_BID); // Old logic check (single condition) double rsi = tech.GetRSI(_Symbol); double ma = tech.GetMA(_Symbol); bool old_exit = (rsi > 70) || (current < ma); // New logic check (requires multiple confirmations) ENUM_EXIT_REASON new_exit = tech.CheckExitSignal(_Symbol, type, entry, current); Print(" Old logic would exit: ", old_exit ? "YES" : "NO"); Print(" New logic would exit: ", new_exit != EXIT_NONE ? "YES" : "NO"); if(old_exit && new_exit == EXIT_NONE) { Print(" ✅ IMPROVED: Old would exit, new won't"); } } // Summary Print("\n========================================"); Print(" VALIDATION SUMMARY"); Print("========================================"); if(all_tests_passed) { Print("\n✅ ALL CRITICAL TESTS PASSED"); Print("\nThe optimized modules are working correctly."); Print("Positions should now stay open longer with:"); Print(" • Minimum 10 bars before exit checks"); Print(" • RSI extremes at 80/20 (not 70/30)"); Print(" • Multiple confirmation requirements"); Print(" • Higher trigger thresholds"); Print(" • Disabled time-based exits"); } else { Print("\n❌ SOME TESTS FAILED"); Print("\nPlease check:"); Print(" 1. Module files are correctly replaced"); Print(" 2. EA is recompiled with new modules"); Print(" 3. Settings are updated as recommended"); } Print("\n📋 NEXT STEPS:"); Print("1. Apply to live EA with recommended settings"); Print("2. Monitor positions for at least 24 hours"); Print("3. Check logs for any premature exit attempts"); Print("4. Run diagnostic script if issues persist"); // Cleanup delete manager; delete tech; delete risk; delete utils; Print("\n========================================"); Print(" VALIDATION TEST COMPLETE"); Print("========================================"); } //+------------------------------------------------------------------+