# Chapter 4: Phase Management System (Deep Dive) ## Understanding Phase-Based Management The Phase Management System is the heart of PME's adaptive protection logic. This chapter explains how it works under the hood. --- ## The Phase Lifecycle ### Initialization When PME detects a new position: ``` 1. Create position tracker 2. Calculate entry price from current price and profit 3. Initialize phase as PHASE_INITIAL 4. Record peak profit (current profit) 5. Set highest_phase_achieved = PHASE_INITIAL 6. Begin monitoring ``` ### Phase Determination Every tick, PME evaluates profit to determine the appropriate phase: ```mql5 if (profit_points < 40) → PHASE_INITIAL else if (profit_points < 60) → PHASE_PROTECTION else if (profit_points < 100) → PHASE_ACCUMULATION else if (profit_points < 200) → PHASE_MAXIMIZATION else if (profit_points < 400) → PHASE_RUNNER else → PHASE_EXTREME ``` ### Phase Transitions When a position moves to a new phase: **Forward Transition** (profit increasing): ``` Old Phase: ACCUMULATION (60-99pts) New Phase: MAXIMIZATION (100-199pts) Actions: 1. Update highest_phase_achieved 2. Calculate new minimum lock (50pts) 3. Apply phase lock if > current lock 4. Log transition 5. Sound alert (optional) ``` **Backward Transition** (profit retracing): ``` Old Phase: MAXIMIZATION (100-199pts) New Phase: ACCUMULATION (60-99pts) Actions: 1. Do NOT downgrade highest_phase_achieved 2. MAINTAIN previous lock (retreat protection) 3. Optionally TIGHTEN lock (retreat multiplier: 1.2×) 4. Log retreat warning 5. Continue monitoring ``` --- ## Phase-Specific Behaviors ### PHASE_INITIAL (0-39 points) **Philosophy**: "Let it breathe" **Actions**: - ✅ Monitor position - ✅ Track peak profit - ✅ Check risk limits - ❌ No stop-loss adjustments - ❌ No profit locking - ❌ No trailing **Rationale**: Positions need room to develop. Early intervention can cut winners short. **Log Output**: ``` [DEBUG] Position #123456 in PHASE_INITIAL (35.0 pts) - no phase lock applied ``` --- ### PHASE_PROTECTION (40-59 points) **Philosophy**: "Protect the gain" **Minimum Lock**: 10 points **Actions**: - ✅ Apply first profit lock - ✅ Begin light trailing (2.5× ATR) - ✅ Prepare for partial closures - ✅ Monitor for phase advancement **Lock Calculation**: ``` Position at 45 points profit: ├─ Base Lock: 10 points (phase minimum) ├─ Progressive: (45 - 10) × 30% = 10.5 points ├─ Total Lock: 10 + 10.5 = 20.5 points ├─ With 50% breathing: 45 × 50% = 22.5 points └─ Effective Lock: MAX(20.5, 22.5) = 22.5 points (but min 10) Final: 22.5 points ``` **Log Output**: ``` [INFO] Position #123456 transitioning from Initial to Protection (Peak: 45.0, Current: 44.0) [INFO] Applied phase lock for #123456: Phase Protection lock: 22.5 pts (was 0.0 pts) ``` --- ### PHASE_ACCUMULATION (60-99 points) **Philosophy**: "Build the position" **Minimum Lock**: 25 points **Actions**: - ✅ Increase lock to 25pts minimum - ✅ Active trailing (2.0× ATR) - ✅ Consider first partial close (if enabled) - ✅ Monitor momentum **Strategy**: - If momentum weak: Prepare to bank profits via partial close - If momentum strong: Keep full position, trail loosely **Log Output**: ``` [INFO] Position #123456 transitioning from Protection to Accumulation (Peak: 65.0, Current: 63.0) [INFO] Phase Lock Calc #123456: Phase=Accumulation, Peak=65.0, Current=63.0, BaseLock=25.0, ProgLock=12.0, BreathingRoom=32.5, EffectiveLock=37.0 ``` --- ### PHASE_MAXIMIZATION (100-199 points) **Philosophy**: "Actively manage" **Minimum Lock**: 50 points **Actions**: - ✅ Lock minimum 50pts - ✅ Progressive locking at 50% of excess - ✅ Tighter trailing (1.5× ATR) - ✅ Second partial close opportunity - ✅ Active retracement monitoring **Risk Check**: - Max retracement allowed: 60% from peak - If exceeded: Warn or close position **Lock Calculation**: ``` Position at 150 points profit: ├─ Base Lock: 50 points ├─ Progressive: (150 - 50) × 50% = 50 points ├─ Total Lock: 50 + 50 = 100 points ├─ With 50% breathing: 150 × 50% = 75 points └─ Effective Lock: MAX(100, 75) = 100 points Final: 100 points ``` --- ### PHASE_RUNNER (200-399 points) **Philosophy**: "Let winners run" **Minimum Lock**: 100 points **Actions**: - ✅ Lock minimum 100pts (significant profit secured) - ✅ Very wide trailing (3.0× ATR) - ✅ Third partial close (create runner) - ✅ Mark as "runner_active" - ✅ Reduce management frequency **Purpose**: - Allow position to capture rare, extended moves - Accept wider swings for potential outsized gains - Runner portion typically 35-50% of original size **Log Output**: ``` [INFO] Position #123456 in RUNNER phase - 35.00% remaining [INFO] Runners Created: 1 ``` --- ### PHASE_EXTREME (400+ points) **Philosophy**: "Protect the exceptional" **Minimum Lock**: 200 points **Actions**: - ✅ Lock minimum 200pts - ✅ Ultra-wide trailing (4.0× ATR) - ✅ Final partial close opportunity - ✅ Monitor for exhaustion signals - ⚠️ Prepare for reversal **Exhaustion Detection**: - Time: Position in phase > 100 bars - Momentum: Score < 0.3 - Retracement: > 40% from peak **Log Output**: ``` [INFO] Position #123456 in EXTREME phase - monitoring for exhaustion [WARNING] Position #123456 - exhaustion detected at extreme profit [INFO] Extreme Profits: 1 ``` --- ## Retreat Protection ### What Is It? When a position retraces from a higher phase to a lower one, PME maintains the lock from the highest phase achieved. ### Example ``` Timeline: T1: +110 pts → MAXIMIZATION (lock 50pts) T2: +180 pts → Still MAXIMIZATION (lock increased to 75pts) T3: +85 pts → Retreats to ACCUMULATION Traditional System: └─ Would apply ACCUMULATION lock (25pts) ❌ PME Retreat Protection: └─ Maintains MAXIMIZATION lock (75pts) ✅ └─ Optionally tightens by 20%: 75 × 1.2 = 90pts ✅ ``` ### Why It Matters Prevents "lock downgrade" during retracements, ensuring maximum profit protection is always maintained. --- ## Breathing Room System ### Purpose Allow natural market fluctuations without prematurely exiting profitable positions. ### Default: 50% Breathing Room ``` Peak Profit: 100 points Breathing Room: 50% Calculation: ├─ Allow retracement to: 100 × (1 - 0.50) = 50 points └─ Set SL to lock 50 points minimum Result: Position can retrace 50% from peak before hitting SL ``` ### Dynamic Adjustment Breathing room adapts to market conditions: | Condition | Breathing Room | Effect | |-----------|---------------|--------| | Strong momentum | Reduced to 40% | Tighter lock, faster banking | | Weak momentum | Increased to 60% | Looser lock, more room | | High volatility | Increased to 60% | Avoid whipsaw exits | | Low volatility | Reduced to 40% | Take profits efficiently | --- ## Lock Calculation Deep Dive ### Formula Components ``` 1. Base Lock = Phase minimum (10, 25, 50, 100, 200) 2. Progressive Lock = (Peak - Base) × Phase % 3. Total Lock = Base + Progressive 4. Breathing Room Applied = Peak × (1 - breathing_room_%) 5. Effective Lock = MAX(Total Lock, Breathing Lock) 6. Dynamic Adjustments (momentum, volatility, retreat) 7. Final Lock = MIN(Effective Lock, Peak × 0.9) ``` ### Step-by-Step Example ``` Position Details: ├─ Entry: 1.0850 ├─ Peak: 1.0970 (+120 points) ├─ Current: 1.0960 (+110 points) └─ Phase: MAXIMIZATION Step 1: Base Lock └─ MAXIMIZATION minimum = 50 points Step 2: Progressive Lock ├─ Excess profit = 120 - 50 = 70 points ├─ MAXIMIZATION lock % = 50% └─ Progressive = 70 × 0.50 = 35 points Step 3: Total Lock └─ 50 + 35 = 85 points Step 4: Breathing Room ├─ 50% breathing room ├─ Lock from breathing = 120 × 0.50 = 60 points └─ (Less than total lock, so total lock wins) Step 5: Effective Lock └─ MAX(85, 60) = 85 points Step 6: Dynamic Adjustments ├─ Check momentum: 1.2 (strong) → Reduce by 30% = 85 × 0.7 = 59.5 ├─ Check volatility: 0.9 (low) → No adjustment ├─ Check retreat: No → No adjustment └─ After adjustments: 59.5 points Step 7: Bounds Check ├─ Ensure >= phase minimum: 59.5 >= 50 ✓ ├─ Ensure <= 90% of peak: 59.5 <= 108 ✓ └─ Final lock: 59.5 points Step 8: Convert to Price ├─ Entry price: 1.0850 ├─ Lock: 59.5 points × 0.00001 = 0.00595 └─ SL price: 1.0850 + 0.00595 = 1.09095 Result: Stop-loss set at 1.09095 ``` --- ## Monitoring and Logs ### Debug Logging When debug logging is enabled (LOG_DEBUG level), you'll see detailed calculations: ``` [DEBUG] Phase Lock Calc #123456: Phase=Maximization, Peak=120.0, Current=110.0, BaseLock=50.0, ProgLock=35.0, BreathingRoom=60.0, EffectiveLock=59.5 [DEBUG] Phase Lock SL #123456: Entry=1.08500, Current=1.09600, SL=1.09095 (LONG) ``` ### Production Logging In normal operation (LOG_INFO level), you'll see: ``` [INFO] Position #123456 transitioning from Accumulation to Maximization (Peak: 120.0, Current: 110.0) [INFO] Applied phase lock for #123456: Phase Maximization lock: 59.5 pts (was 37.0 pts) ``` --- ## Best Practices ### 1. Don't Micro-Manage Phase Triggers - Default triggers (40/60/100/200/400) are well-tested - Adjusting too early can cut winners - Adjusting too late reduces protection ### 2. Respect Breathing Room - 50% is optimal for most strategies - Reduce only if you have high win rate - Increase if trading volatile instruments ### 3. Trust Retreat Protection - Don't manually intervene during retracements - PME maintains highest lock automatically - Manual SL adjustments may conflict ### 4. Monitor Phase Distribution - Dashboard shows positions by phase - Healthy mix indicates good profit capture - Too many in INITIAL = early exits elsewhere - Too many in EXTREME = rare but profitable --- **Return to**: [Main README](README.md)