feat: Implement Equity Curve Trading for automatic drawdown protection
NEW MODULE: equity_curve_trading.py - EquityCurveManager class for meta-strategy control - Tracks equity history after each trade - Calculates Moving Average over configurable period (default: 10 trades) - Soft Mode: Reduces lot size to 50% when equity < MA - Hard Mode: Completely stops trading when equity < MA - Recovery detection with buffer percentage - Persistent storage in equity_curve_history.json CONFIGURATION: - ma_period: 10 trades (Moving Average window) - min_trades_required: 5 (warmup period) - soft_mode: True (reduce lots instead of stopping) - soft_mode_multiplier: 0.5 (50% lots when under MA) - recovery_buffer_pct: 0.5% (buffer for recovery status) INTEGRATION: - Added to Cell 78 (Advanced Optimizations setup) - Integrated in enhanced_trading_check_wrapper (Cells 85, 90) - Added lot_multiplier parameter to execute_trade_v2_adaptive - Equity update after each successful trade EXAMPLE FLOW: 1. Before trade: Check should_trade() → returns (allowed, reason, lot_multiplier) 2. If equity < MA: lot_multiplier = 0.5 (or 0.0 in hard mode) 3. Position size adjusted: volume = volume * lot_multiplier 4. After trade: update_equity() called to track new equity BENEFITS: - Automatic protection during losing streaks - Reduces exposure when strategy underperforms - Capitalizes fully when strategy is working - No emotional decisions needed 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1230,7 +1230,9 @@
|
||||
" debug=True,\n",
|
||||
" # Enhanced Scoring Overrides\n",
|
||||
" signal_info_override=None,\n",
|
||||
" confidence_override=None\n",
|
||||
" confidence_override=None,\n",
|
||||
" # Equity Curve Trading\n",
|
||||
" lot_multiplier=1.0\n",
|
||||
"):\n",
|
||||
" \"\"\"\n",
|
||||
" V1.6 Adaptive Complete Trade-Ausführung:\n",
|
||||
@@ -1351,6 +1353,13 @@
|
||||
" else:\n",
|
||||
" volume = TRADING_CONFIG[\"lot_sizing\"][\"default_lot\"]\n",
|
||||
" \n",
|
||||
" # Apply Equity Curve lot multiplier\n",
|
||||
" if lot_multiplier != 1.0:\n",
|
||||
" original_volume = volume\n",
|
||||
" volume = round(volume * lot_multiplier, 2)\n",
|
||||
" volume = max(TRADING_CONFIG[\"lot_sizing\"][\"min_lot\"], volume) # Ensure minimum\n",
|
||||
" print(f\"📈 Equity Curve: Lot adjusted {original_volume:.2f} → {volume:.2f} ({lot_multiplier:.0%})\")\n",
|
||||
" \n",
|
||||
" # Log Trade Info\n",
|
||||
" print(f\"\\n🚀 V1.6 ADAPTIVE COMPLETE TRADE EXECUTION\")\n",
|
||||
" print(f\"Direction: {'LONG' if entry_signal == 1 else 'SHORT'}\")\n",
|
||||
@@ -3011,6 +3020,7 @@
|
||||
"from dynamic_threshold_optimizer import DynamicThresholdOptimizer, auto_optimize_thresholds\n",
|
||||
"from enhanced_signal_scoring import EnhancedSignalScorer\n",
|
||||
"from enhanced_trailing_stop import EnhancedTrailingStopManager, create_enhanced_position_monitor\n",
|
||||
"from equity_curve_trading import EquityCurveManager\n",
|
||||
"\n",
|
||||
"print(\"🚀 INITIALIZING ADVANCED OPTIMIZATIONS...\")\n",
|
||||
"print(\"=\" * 70)\n",
|
||||
@@ -3075,6 +3085,18 @@
|
||||
"print(\"✅ Enhanced Trailing Stop Manager initialized\")\n",
|
||||
"print()\n",
|
||||
"\n",
|
||||
"# 4. Equity Curve Trading\n",
|
||||
"equity_curve_manager = EquityCurveManager(\n",
|
||||
" ma_period=10, # MA über 10 Trades\n",
|
||||
" min_trades_required=5, # Warmup: 5 Trades\n",
|
||||
" soft_mode=True, # Reduzierte Lots statt Stop\n",
|
||||
" soft_mode_multiplier=0.5, # 50% Lots wenn unter MA\n",
|
||||
" recovery_buffer_pct=0.5, # 0.5% über MA = Recovery\n",
|
||||
" data_file=\"equity_curve_history.json\"\n",
|
||||
")\n",
|
||||
"print(\"✅ Equity Curve Manager initialized\")\n",
|
||||
"print()\n",
|
||||
"\n",
|
||||
"# 4. Run initial threshold optimization\n",
|
||||
"print(\"🔄 Running initial threshold optimization...\")\n",
|
||||
"try:\n",
|
||||
@@ -3092,6 +3114,7 @@
|
||||
"print(\" • Dynamic Thresholds: ✅ (auto-adjusts daily)\")\n",
|
||||
"print(\" • Enhanced Scoring: ✅ (5-factor analysis)\")\n",
|
||||
"print(\" • Enhanced Trailing: ✅ (multi-tier protection)\")\n",
|
||||
"print(\" • Equity Curve Trading: ✅ (auto-pause on drawdown)\")\n",
|
||||
"print()\n",
|
||||
"print(\"💡 Tip: Use 'threshold_optimizer.generate_report()' for details\")"
|
||||
]
|
||||
@@ -3362,6 +3385,14 @@
|
||||
"\n",
|
||||
" print(f\"✅ Position-Check OK: {position_info['count']}/{max_positions}\")\n",
|
||||
"\n",
|
||||
" # SCHRITT 1.5: EQUITY CURVE CHECK\n",
|
||||
" ec_allowed, ec_reason, lot_multiplier = equity_curve_manager.should_trade()\n",
|
||||
" print(f\"📈 Equity Curve: {ec_reason}\")\n",
|
||||
" \n",
|
||||
" if not ec_allowed:\n",
|
||||
" print(f\"⛔ TRADE BLOCKIERT durch Equity Curve Filter\")\n",
|
||||
" return None\n",
|
||||
"\n",
|
||||
" # SCHRITT 2: Signal Analysis (wie vorher)\n",
|
||||
" signal_info = extended_top_down_v2_adaptive(symbol)\n",
|
||||
" if signal_info is None:\n",
|
||||
@@ -3424,8 +3455,14 @@
|
||||
" result = execute_trade_v2_adaptive(\n",
|
||||
" symbol=symbol,\n",
|
||||
" signal_info_override=signal_info,\n",
|
||||
" confidence_override=final_confidence # ← Use hybrid score!\n",
|
||||
" confidence_override=final_confidence, # ← Use hybrid score!\n",
|
||||
" lot_multiplier=lot_multiplier # ← Equity Curve adjustment\n",
|
||||
" )\n",
|
||||
" \n",
|
||||
" # Update Equity Curve nach Trade\n",
|
||||
" if result is not None:\n",
|
||||
" equity_curve_manager.update_equity()\n",
|
||||
" print(f\"📈 Equity Curve updated\")\n",
|
||||
"\n",
|
||||
" return result\n",
|
||||
" else:\n",
|
||||
@@ -3629,6 +3666,14 @@
|
||||
"\n",
|
||||
" print(f\"✅ Position-Check OK: {position_info['count']}/{max_positions}\")\n",
|
||||
"\n",
|
||||
" # SCHRITT 1.5: EQUITY CURVE CHECK\n",
|
||||
" ec_allowed, ec_reason, lot_multiplier = equity_curve_manager.should_trade()\n",
|
||||
" print(f\"📈 Equity Curve: {ec_reason}\")\n",
|
||||
" \n",
|
||||
" if not ec_allowed:\n",
|
||||
" print(f\"⛔ TRADE BLOCKIERT durch Equity Curve Filter\")\n",
|
||||
" return None\n",
|
||||
"\n",
|
||||
" # SCHRITT 2: Signal Analysis (wie vorher)\n",
|
||||
" signal_info = extended_top_down_v2_adaptive(symbol)\n",
|
||||
" if signal_info is None:\n",
|
||||
@@ -3691,8 +3736,14 @@
|
||||
" result = execute_trade_v2_adaptive(\n",
|
||||
" symbol=symbol,\n",
|
||||
" signal_info_override=signal_info,\n",
|
||||
" confidence_override=final_confidence # ← Use hybrid score!\n",
|
||||
" confidence_override=final_confidence, # ← Use hybrid score!\n",
|
||||
" lot_multiplier=lot_multiplier # ← Equity Curve adjustment\n",
|
||||
" )\n",
|
||||
" \n",
|
||||
" # Update Equity Curve nach Trade\n",
|
||||
" if result is not None:\n",
|
||||
" equity_curve_manager.update_equity()\n",
|
||||
" print(f\"📈 Equity Curve updated\")\n",
|
||||
"\n",
|
||||
" return result\n",
|
||||
" else:\n",
|
||||
|
||||
Reference in New Issue
Block a user