BREAKING CHANGES:
- M5 mode now enforces all v2.1 delayed BE/trailing parameters
- Graduated stop system replaces legacy disaster stop when enabled
- Max bars limit now triggers hard position close
Changes to PositionManager_PME_Complete.mqh:
1. Max Bars Hard Close Enforcement
- Added check for m_m5_config.max_bars at start of ApplyM5ContrarianManagement()
- Forces EXIT_TIME close when position age exceeds configured limit (300 bars)
- Prevents indefinite position holding in extended phases
2. Graduated Stop-Loss System
- Implements ATR-based phase-progressive stops:
* Phase 1 (0-60 bars): 3.5 ATR wide initial protection
* Phase 2 (60-180 bars): 2.5 ATR tightened stop
* Phase 3 (180+ bars): 2.0 ATR mature stop
- Replaces legacy disaster stop when m_config.use_graduated_stops enabled
- Falls back to disaster stop (150pt @ -100pt) if graduated stops disabled
- Updates m_positions[].current_sl after successful modification
3. Delayed Breakeven Enforcement (v2.1)
- Respects m_config.breakeven_min_bars (20 bars minimum age)
- Respects m_config.breakeven_min_profit_bars (5 consecutive profit bars)
- Applied to both Phase 1 fast BE (25pts) and Phase 2 maturity BE (30pts)
- Logs bar count and consecutive profit bars on activation
4. Delayed Trailing Enforcement (v2.1)
- Respects m_config.trail_min_bars (40 bars minimum age)
- Applied to percentage trail in Phase 2 (30%/40% based on reversal speed)
- Sets trail_activated flag and increments m_metrics.trails_activated
- Logs activation with percentage and bar count
5. M5 Trailing Helper Metric Sync
- Created ApplyM5PercentageTrail() with current_sl sync
- Created ApplyM5PointsTrail() with current_sl sync
- Created ApplyM5DynamicTrail() with current_sl sync
- Standard helpers (ApplyPercentageTrail, etc.) preserved for non-M5 use
- M5 contrarian management now calls M5-specific versions exclusively
- Fixes metric/state desync between MT5 server and in-memory position tracking
Architecture:
- M5 mode continues to bypass standard management path (intentional isolation)
- Standard trailing/technical/time-exit engines remain unused in M5 mode
- Configuration separation maintained: ManagementConfig for standard + v2.1 fields, M5Config for contrarian-specific
- No changes to main EA file (ERMT_PME_2.1_M5.mq5)
Compatibility:
- No breaking changes to standard (non-M5) management path
- Existing M5 backtest results remain valid (behavior refinement only)
- All v2.1 configuration fields now honored in M5 runtime
Overview
To fully integrate the enhanced external trade management system, updates are required to 5 out of 7 existing modules. The updates maintain backward compatibility while adding new functionality for external trade handling.
Module Update Requirements
🟢 No Updates Required (2 modules)
TechnicalAnalysis.mqh - Already provides necessary calculations
EntrySystem.mqh - Only handles EA's own entry signals
🟡 Minor Updates (2 modules)
DataTypes.mqh - Add external trade structures and fields
Utilities.mqh - Enhanced logging for external trades
🟠 Moderate Updates (3 modules)
RiskManager.mqh - Enhanced risk enforcement methods
TradeManager.mqh - Improved stop management for externals
Dashboard.mqh - Display external trade information
Integration Steps
Phase 1: Data Structures (DataTypes.mqh)
Add ENUM_EXTERNAL_STATUS enumeration
Extend ManagedTrade structure with external-specific fields
Add ExternalTradeStats structure for metrics
Update DashboardConfig with show_external flag
Key additions:
external_status - Track state of external trade
source_name - Identify where trade came from
stops_modified - Track if we modified the trade
original_sl/tp - Store original values for comparison
Phase 2: Risk Management (RiskManager.mqh)
Add EnforceRiskRulesEnhanced() method
Implement GetExternalExposure() for risk aggregation
Add UpdateExternalStats() for tracking
Enhance ValidateAndAdjustRiskExternal() method
Key features:
Separate risk calculation for external trades
Cache mechanism for performance
Statistical tracking of external positions
Smart risk adjustment without closing trades
Phase 3: Trade Management (TradeManager.mqh)
Add ApplyDefaultStopsEnhanced() with better logic
Implement OverrideExternalStops() with smart override
Create ManageExternalTrade() with different rules
Add ApplyBreakevenExternal() with wider triggers
Key features:
Smart stop override (only improve, never worsen)
Different management rules for external trades
Respect minimum broker distances
Track modification success/failure rates
Phase 4: User Interface (Dashboard.mqh)
Add CreateExternalSection() for display area
Implement UpdateExternalSection() for real-time updates
Add SetCustomText() for flexible display
Create ShowExternalTrades() toggle method
Key features:
Real-time external trade count and risk
Color-coded risk warnings
List of active external positions
Modification statistics display
Phase 5: Logging (Utilities.mqh)
Add LogExternalTrade() for detailed event logging
Create separate CSV log for external trades
Enhance GenerateReportEnhanced() with external section
Add IdentifyTradeSource() for magic number interpretation
Key features:
Separate CSV log for external trade events
Detailed tracking of all modifications
Source identification from magic numbers
Enhanced reporting with external statistics