Integrate Multi-TF Filter into Notebook

- Cell 25: Info Markdown über neue Lösung
- Cell 26: Alter Filter deaktiviert (auskommentiert)
- Cell 27: Neuer Multi-TF Filter aktiviert
- Cell 28: Test-Cell zum Verifizieren

Ready to run!
This commit is contained in:
2025-12-20 19:16:14 +01:00
parent e9b6662547
commit 39cefd315c
+224 -52
View File
@@ -1207,6 +1207,50 @@
"print(\"✅ V1.6 Adaptive Complete Execute Trade defined\")" "print(\"✅ V1.6 Adaptive Complete Execute Trade defined\")"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 📊 Multi-Timeframe Ranging Filter - AKTIVIERT",
"",
"## ✅ Was wurde geändert?",
"",
"**Problem gelöst**: Alter Filter nutzte nur H1 (ADX 9.90) und blockierte Trades trotz starkem Trend auf D1 (ADX 28.25)",
"",
"**Neue Lösung**:",
"- **Cell 25**: Alter Filter DEAKTIVIERT (auskommentiert)",
"- **Cell 26**: Neuer Multi-TF Filter AKTIVIERT",
"- **Cell 27**: Test-Cell (optional)",
"",
"## 🎯 Wie der neue Filter funktioniert:",
"",
"1. Prüft **3 Timeframes**: H1, H4, D1",
"2. **Gewichtung**: D1 (3x) > H4 (2x) > H1 (1x)",
"3. **Entscheidung**:",
" - D1 ADX > 30 → ERLAUBT",
" - H4+D1 beide > 25 → ERLAUBT",
" - Weighted ADX > 25 → ERLAUBT",
" - Sonst → BLOCKIERT",
"",
"## 🚀 Nächste Schritte:",
"",
"1. **Führen Sie Cell 26 aus** (Multi-TF Filter aktivieren)",
"2. **Führen Sie Cell 27 aus** (Testen - optional)",
"3. **Warten Sie 1-2 Stunden** auf ersten Trade",
"",
"## 📝 Erwartete Ausgabe Cell 27:",
"",
"",
"",
"→ Trades sollten wieder laufen! 🎉",
"",
"---",
"",
"**Installiert**: 2025-12-20",
"**Entwickelt von**: Claude Code Analysis",
""
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
@@ -1218,72 +1262,143 @@
"# ==========================================\n", "# ==========================================\n",
"\n", "\n",
"# Original function wird wrapped\n", "# Original function wird wrapped\n",
"_original_execute_trade_v2_adaptive = execute_trade_v2_adaptive\n", "# [DEAKTIVIERT 20.12.2025] _original_execute_trade_v2_adaptive = execute_trade_v2_adaptive\n",
"\n", "\n",
"def execute_trade_v2_adaptive_with_ranging_filter(\n", "# [DEAKTIVIERT 20.12.2025] def execute_trade_v2_adaptive_with_ranging_filter(\n",
" symbol=\"XAUUSD\",\n", "# [DEAKTIVIERT 20.12.2025] symbol=\"XAUUSD\",\n",
" atr_mult=1.5,\n", "# [DEAKTIVIERT 20.12.2025] atr_mult=1.5,\n",
" base_confidence=60,\n", "# [DEAKTIVIERT 20.12.2025] base_confidence=60,\n",
" max_risk_per_trade=0.01,\n", "# [DEAKTIVIERT 20.12.2025] max_risk_per_trade=0.01,\n",
" risk_filter=True,\n", "# [DEAKTIVIERT 20.12.2025] risk_filter=True,\n",
" min_atr=0.0008,\n", "# [DEAKTIVIERT 20.12.2025] min_atr=0.0008,\n",
" use_pullback_entry=False,\n", "# [DEAKTIVIERT 20.12.2025] use_pullback_entry=False,\n",
" max_positions=1,\n", "# [DEAKTIVIERT 20.12.2025] max_positions=1,\n",
" strategy_name=\"TradingBot_V1.6\",\n", "# [DEAKTIVIERT 20.12.2025] strategy_name=\"TradingBot_V1.6\",\n",
" debug=True):\n", "# [DEAKTIVIERT 20.12.2025] debug=True):\n",
" \"\"\"\n", "# [DEAKTIVIERT 20.12.2025] \"\"\"\n",
" Wrapper für execute_trade_v2_adaptive mit Ranging Filter\n", "# [DEAKTIVIERT 20.12.2025] Wrapper für execute_trade_v2_adaptive mit Ranging Filter\n",
" Blocks trading in ranging markets - they cause 100% of losses!\n", "# [DEAKTIVIERT 20.12.2025] Blocks trading in ranging markets - they cause 100% of losses!\n",
" \"\"\"\n", "# [DEAKTIVIERT 20.12.2025] \"\"\"\n",
"\n", "\n",
" # Quick check: Get signal info first\n", " # Quick check: Get signal info first\n",
" signal_info = extended_top_down_v2_adaptive(symbol)\n", "# [DEAKTIVIERT 20.12.2025] signal_info = extended_top_down_v2_adaptive(symbol)\n",
" if signal_info is None:\n", "# [DEAKTIVIERT 20.12.2025] if signal_info is None:\n",
" return None\n", "# [DEAKTIVIERT 20.12.2025] return None\n",
"\n", "\n",
" market_regime = signal_info.get(\"market_regime\", {})\n", "# [DEAKTIVIERT 20.12.2025] market_regime = signal_info.get(\"market_regime\", {})\n",
" regime = market_regime.get('regime', 'unknown')\n", "# [DEAKTIVIERT 20.12.2025] regime = market_regime.get('regime', 'unknown')\n",
" adx = market_regime.get('adx', 0)\n", "# [DEAKTIVIERT 20.12.2025] adx = market_regime.get('adx', 0)\n",
"\n", "\n",
" # 🛑 RANGING FILTER - Block ALL ranging market trades\n", " # 🛑 RANGING FILTER - Block ALL ranging market trades\n",
" if regime == 'ranging':\n", "# [DEAKTIVIERT 20.12.2025] if regime == 'ranging':\n",
" if debug:\n", "# [DEAKTIVIERT 20.12.2025] if debug:\n",
" print(f\"\\n🛑 TRADE BLOCKIERT: Ranging Market!\")\n", "# [DEAKTIVIERT 20.12.2025] print(f\"\\n🛑 TRADE BLOCKIERT: Ranging Market!\")\n",
" print(f\" ADX: {adx:.1f} (< 25 = Ranging)\")\n", "# [DEAKTIVIERT 20.12.2025] print(f\" ADX: {adx:.1f} (< 25 = Ranging)\")\n",
" print(f\" 📊 Ranging Performance: 0% Win Rate, 20 consecutive losses\")\n", "# [DEAKTIVIERT 20.12.2025] print(f\" 📊 Ranging Performance: 0% Win Rate, 20 consecutive losses\")\n",
" print(f\" ✅ Filter is protecting you from losses!\")\n", "# [DEAKTIVIERT 20.12.2025] print(f\" ✅ Filter is protecting you from losses!\")\n",
" return None\n", "# [DEAKTIVIERT 20.12.2025] return None\n",
"\n", "\n",
" # Additional safety: Even in trending, ADX must be > 25\n", " # Additional safety: Even in trending, ADX must be > 25\n",
" if regime == 'trending' and adx < 25:\n", "# [DEAKTIVIERT 20.12.2025] if regime == 'trending' and adx < 25:\n",
" if debug:\n", "# [DEAKTIVIERT 20.12.2025] if debug:\n",
" print(f\"\\n🛑 TRADE BLOCKIERT: Weak Trend!\")\n", "# [DEAKTIVIERT 20.12.2025] print(f\"\\n🛑 TRADE BLOCKIERT: Weak Trend!\")\n",
" print(f\" ADX: {adx:.1f} (< 25 = too weak)\")\n", "# [DEAKTIVIERT 20.12.2025] print(f\" ADX: {adx:.1f} (< 25 = too weak)\")\n",
" return None\n", "# [DEAKTIVIERT 20.12.2025] return None\n",
"\n", "\n",
" # ✅ Regime check passed - execute original function\n", " # ✅ Regime check passed - execute original function\n",
" if debug:\n", "# [DEAKTIVIERT 20.12.2025] if debug:\n",
" print(f\"✅ REGIME CHECK PASSED: {regime.upper()} (ADX {adx:.1f})\")\n", "# [DEAKTIVIERT 20.12.2025] print(f\"✅ REGIME CHECK PASSED: {regime.upper()} (ADX {adx:.1f})\")\n",
"\n", "\n",
" return _original_execute_trade_v2_adaptive(\n", "# [DEAKTIVIERT 20.12.2025] return _original_execute_trade_v2_adaptive(\n",
" symbol=symbol,\n", "# [DEAKTIVIERT 20.12.2025] symbol=symbol,\n",
" atr_mult=atr_mult,\n", "# [DEAKTIVIERT 20.12.2025] atr_mult=atr_mult,\n",
" base_confidence=base_confidence,\n", "# [DEAKTIVIERT 20.12.2025] base_confidence=base_confidence,\n",
" max_risk_per_trade=max_risk_per_trade,\n", "# [DEAKTIVIERT 20.12.2025] max_risk_per_trade=max_risk_per_trade,\n",
" risk_filter=risk_filter,\n", "# [DEAKTIVIERT 20.12.2025] risk_filter=risk_filter,\n",
" min_atr=min_atr,\n", "# [DEAKTIVIERT 20.12.2025] min_atr=min_atr,\n",
" use_pullback_entry=use_pullback_entry,\n", "# [DEAKTIVIERT 20.12.2025] use_pullback_entry=use_pullback_entry,\n",
" max_positions=max_positions,\n", "# [DEAKTIVIERT 20.12.2025] max_positions=max_positions,\n",
" strategy_name=strategy_name,\n", "# [DEAKTIVIERT 20.12.2025] strategy_name=strategy_name,\n",
" debug=debug\n", "# [DEAKTIVIERT 20.12.2025] debug=debug\n",
" )\n", "# [DEAKTIVIERT 20.12.2025] )\n",
"\n", "\n",
"# Replace original with wrapped version\n", "# Replace original with wrapped version\n",
"execute_trade_v2_adaptive = execute_trade_v2_adaptive_with_ranging_filter\n", "# [DEAKTIVIERT 20.12.2025] execute_trade_v2_adaptive = execute_trade_v2_adaptive_with_ranging_filter\n",
"\n", "\n",
"print(\"✅ Ranging Filter activated!\")\n", "# [DEAKTIVIERT 20.12.2025] print(\"✅ Ranging Filter activated!\")\n",
"print(\" 🛑 Blocks ALL ranging market trades\")\n", "# [DEAKTIVIERT 20.12.2025] print(\" 🛑 Blocks ALL ranging market trades\")\n",
"print(\" ✅ Only allows trending markets with ADX > 25\")\n" "# [DEAKTIVIERT 20.12.2025] print(\" ✅ Only allows trending markets with ADX > 25\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# ==========================================",
"# 🎯 MULTI-TIMEFRAME RANGING FILTER (20.12.2025)",
"# ==========================================",
"# Verbesserte Ranging-Erkennung basierend auf H1, H4, und D1",
"",
"from multi_timeframe_regime_filter import create_multi_timeframe_ranging_filter",
"",
"# Backup der Original-Funktion (falls noch nicht geschehen)",
"if '_original_execute_trade_v2_adaptive' not in dir():",
" _original_execute_trade_v2_adaptive = execute_trade_v2_adaptive",
"",
"# Ersetze mit Multi-TF Filter",
"execute_trade_v2_adaptive = create_multi_timeframe_ranging_filter(",
" _original_execute_trade_v2_adaptive",
")",
"",
"print(\"✅ Multi-Timeframe Ranging Filter aktiviert!\")",
"print(\" Prüft: H1, H4, D1\")",
"print(\" Gewichtung: D1 (3x) > H4 (2x) > H1 (1x)\")",
"print(\" Threshold: ADX > 25\")",
"print(\"\")",
"print(\"📊 Entscheidungslogik:\")",
"print(\" 1. D1 ADX > 30 → ERLAUBT (starker Trend)\")",
"print(\" 2. H4+D1 beide > 25 → ERLAUBT (bestätigter Trend)\")",
"print(\" 3. Weighted ADX > 25 → ERLAUBT (Gesamtbild)\")",
"print(\" 4. Sonst → BLOCKIERT (Ranging)\")",
""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# ==========================================",
"# 🧪 TEST: Multi-Timeframe Regime Filter",
"# ==========================================",
"# Führe diese Cell aus um den Filter zu testen",
"",
"from multi_timeframe_regime_filter import detect_multi_timeframe_regime",
"",
"print(\"🧪 TESTING MULTI-TIMEFRAME REGIME FILTER\")",
"print(\"=\" * 70)",
"print()",
"",
"# Test-Run",
"result = detect_multi_timeframe_regime(\"XAUUSD\", adx_threshold=25, debug=True)",
"",
"print()",
"print(\"📋 ERGEBNIS:\")",
"print(f\" Trading Allowed: {result['allowed']}\")",
"print(f\" Regime: {result['regime']}\")",
"print(f\" Weighted ADX: {result['weighted_adx']:.1f}\")",
"print()",
"",
"if result['allowed']:",
" print(\"✅ FILTER ERLAUBT TRADES!\")",
" print(\" → Bot wird bei nächstem Scheduler-Run traden (wenn andere Bedingungen passen)\")",
"else:",
" print(\"🛑 FILTER BLOCKIERT TRADES\")",
" print(f\" → Grund: {result['reason']}\")",
""
] ]
}, },
{ {
@@ -2311,6 +2426,63 @@
" print(f\"{emoji} {session}: {reason}\")" " print(f\"{emoji} {session}: {reason}\")"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"📊 ADX auf verschiedenen Timeframes:\n",
"\n",
"M15 : ADX = 21.63 | Preis-Change (10 bars): -0.19%\n",
"H1 : ADX = 9.90 | Preis-Change (10 bars): +0.27%\n",
"H4 : ADX = 23.37 | Preis-Change (10 bars): +0.35%\n",
"D1 : ADX = 28.25 | Preis-Change (10 bars): +3.53%\n",
"\n",
"💰 Aktueller Preis: 4338.47\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025-12-20 19:12:54,206 - INFO - Running job \"PositionMonitor.check_open_positions (trigger: interval[0:01:00], next run at: 2025-12-20 19:13:54 CET)\" (scheduled at 2025-12-20 19:12:54.202603+01:00)\n",
"2025-12-20 19:12:54,208 - INFO - Job \"PositionMonitor.check_open_positions (trigger: interval[0:01:00], next run at: 2025-12-20 19:13:54 CET)\" executed successfully\n",
"2025-12-20 19:12:54,209 - INFO - Running job \"<lambda> (trigger: interval[0:01:00], next run at: 2025-12-20 19:13:54 CET)\" (scheduled at 2025-12-20 19:12:54.203646+01:00)\n",
"2025-12-20 19:12:54,223 - INFO - Job \"<lambda> (trigger: interval[0:01:00], next run at: 2025-12-20 19:13:54 CET)\" executed successfully\n",
"2025-12-20 19:13:00,000 - INFO - Running job \"create_protected_trading_check.<locals>.protected_check (trigger: cron[minute='*'], next run at: 2025-12-20 19:14:00 CET)\" (scheduled at 2025-12-20 19:13:00+01:00)\n",
"2025-12-20 19:13:00,014 - INFO - Job \"create_protected_trading_check.<locals>.protected_check (trigger: cron[minute='*'], next run at: 2025-12-20 19:14:00 CET)\" executed successfully\n",
"2025-12-20 19:13:54,204 - INFO - Running job \"PositionMonitor.check_open_positions (trigger: interval[0:01:00], next run at: 2025-12-20 19:14:54 CET)\" (scheduled at 2025-12-20 19:13:54.202603+01:00)\n",
"2025-12-20 19:13:54,204 - INFO - Running job \"<lambda> (trigger: interval[0:01:00], next run at: 2025-12-20 19:14:54 CET)\" (scheduled at 2025-12-20 19:13:54.203646+01:00)\n",
"2025-12-20 19:13:54,213 - INFO - Job \"<lambda> (trigger: interval[0:01:00], next run at: 2025-12-20 19:14:54 CET)\" executed successfully\n",
"2025-12-20 19:13:54,207 - INFO - Job \"PositionMonitor.check_open_positions (trigger: interval[0:01:00], next run at: 2025-12-20 19:14:54 CET)\" executed successfully\n",
"2025-12-20 19:14:00,012 - INFO - Running job \"create_protected_trading_check.<locals>.protected_check (trigger: cron[minute='*'], next run at: 2025-12-20 19:15:00 CET)\" (scheduled at 2025-12-20 19:14:00+01:00)\n",
"2025-12-20 19:14:00,019 - INFO - Job \"create_protected_trading_check.<locals>.protected_check (trigger: cron[minute='*'], next run at: 2025-12-20 19:15:00 CET)\" executed successfully\n"
]
}
],
"source": [
"# Verschiedene Timeframes checken\n",
"print(\"📊 ADX auf verschiedenen Timeframes:\\n\")\n",
"\n",
"for tf_name, tf in [('M15', mt.TIMEFRAME_M15), ('H1', mt.TIMEFRAME_H1), ('H4', mt.TIMEFRAME_H4), ('D1', mt.TIMEFRAME_D1)]:\n",
" rates = mt.copy_rates_from_pos(\"XAUUSD\", tf, 0, 100)\n",
" df = pd.DataFrame(rates)\n",
" adx_data = ta.adx(df['high'], df['low'], df['close'], length=14)\n",
" current_adx = adx_data['ADX_14'].iloc[-1]\n",
" \n",
" # Preis letzte 10 Bars\n",
" price_change = ((df['close'].iloc[-1] - df['close'].iloc[-10]) / df['close'].iloc[-10]) * 100\n",
" \n",
" print(f\"{tf_name:4s}: ADX = {current_adx:5.2f} | Preis-Change (10 bars): {price_change:+.2f}%\")\n",
"\n",
"# Aktueller Preis\n",
"print(f\"\\n💰 Aktueller Preis: {mt.symbol_info_tick('XAUUSD').bid:.2f}\")"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,