feat: Add Trend Reversal Detector with multi-signal analysis
Deploy to Windows VPS / deploy (push) Has been cancelled
Deploy to Windows VPS / deploy (push) Has been cancelled
New features: - Reversal Detector with 5 detection signals: - RSI Divergence (bearish/bullish) - EMA Slope Change detection - Volume Spike analysis - Candlestick patterns (Doji, Engulfing, Hammer, Pin Bar) - Break of Structure detection - Integrated into enhanced_trading_check_wrapper (SCHRITT 2.5) - Defensive mode: blocks trades at 70%+ reversal score - Lot size reduction at 30-69% reversal score - Enable Overlap session (13:00-16:00 UTC) Files added: - reversal_detector.py: Core detection algorithms - reversal_integration.py: Bot integration wrapper - REVERSAL_DETECTOR_INTEGRATION.md: Documentation Modified: - TradingBot notebook: Added reversal check integration - session_filter_patch.py: Enabled overlap session Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b5b91224df
commit
ce4e961541
5 files changed
+1623
-177
No files matched your search
@@ -0,0 +1,221 @@
|
||||
# 🔄 Reversal Detector Integration Guide
|
||||
|
||||
## Schnell-Integration
|
||||
|
||||
### Schritt 1: Import hinzufügen (neue Cell nach den Imports)
|
||||
|
||||
```python
|
||||
# ==========================================
|
||||
# 🔄 REVERSAL DETECTOR INTEGRATION
|
||||
# ==========================================
|
||||
|
||||
from reversal_integration import (
|
||||
reversal_detector,
|
||||
check_reversal_risk,
|
||||
get_reversal_status,
|
||||
enable_reversal_check,
|
||||
disable_reversal_check,
|
||||
REVERSAL_CONFIG
|
||||
)
|
||||
|
||||
print(get_reversal_status())
|
||||
```
|
||||
|
||||
### Schritt 2: In `enhanced_trading_check_wrapper` einfügen
|
||||
|
||||
Füge nach **SCHRITT 2: Signal Analysis** und vor **SCHRITT 3: ENHANCED SIGNAL SCORING** folgenden Code ein:
|
||||
|
||||
```python
|
||||
# ==========================================
|
||||
# ⭐ SCHRITT 2.5: REVERSAL CHECK (NEU!)
|
||||
# ==========================================
|
||||
from reversal_integration import check_reversal_risk
|
||||
|
||||
reversal_result = check_reversal_risk(signal_info, symbol)
|
||||
|
||||
print(f"\n🔄 Reversal Check: {reversal_result['action']}")
|
||||
print(f" Score: {reversal_result['reversal_score']}%")
|
||||
print(f" Reason: {reversal_result['reason']}")
|
||||
|
||||
if not reversal_result['should_trade']:
|
||||
print(f"⛔ TRADE BLOCKIERT durch Reversal Detector!")
|
||||
return None
|
||||
|
||||
# Reversal Lot Multiplier mit Equity Curve kombinieren
|
||||
if reversal_result['lot_multiplier'] < 1.0:
|
||||
lot_multiplier *= reversal_result['lot_multiplier']
|
||||
print(f"📉 Reversal: Lot Multiplier angepasst auf {lot_multiplier:.0%}")
|
||||
# ==========================================
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Vollständige enhanced_trading_check_wrapper mit Reversal Check
|
||||
|
||||
```python
|
||||
def enhanced_trading_check_wrapper(symbol="XAUUSD", debug=False):
|
||||
"""
|
||||
Enhanced wrapper around execute_trade_v2_adaptive
|
||||
Adds multi-factor signal scoring before execution
|
||||
+ Reversal Detection (NEU!)
|
||||
"""
|
||||
|
||||
try:
|
||||
# ⭐ SCHRITT 0: SESSION CHECK
|
||||
from session_filter_patch import is_session_allowed
|
||||
current_session = rhythm_manager.get_current_session()
|
||||
session_allowed, session_reason = is_session_allowed(current_session)
|
||||
|
||||
if not session_allowed:
|
||||
print(f"⛔ SESSION BLOCKED: {current_session.upper()}")
|
||||
print(f" Reason: {session_reason}")
|
||||
return None
|
||||
|
||||
print(f"✅ Session OK: {current_session.upper()}")
|
||||
|
||||
# SCHRITT 1: Position Check
|
||||
max_positions = TRADING_CONFIG['risk']['max_positions']
|
||||
has_position, position_info = check_existing_positions(symbol)
|
||||
|
||||
if position_info['count'] >= max_positions:
|
||||
if debug:
|
||||
print(f"🛑 TRADE BLOCKIERT: {position_info['count']}/{max_positions} Positionen aktiv")
|
||||
return None
|
||||
|
||||
print(f"✅ Position-Check OK: {position_info['count']}/{max_positions}")
|
||||
|
||||
# SCHRITT 1.5: EQUITY CURVE CHECK
|
||||
ec_allowed, ec_reason, lot_multiplier = equity_curve_manager.should_trade()
|
||||
print(f"📈 Equity Curve: {ec_reason}")
|
||||
|
||||
if not ec_allowed:
|
||||
print(f"⛔ TRADE BLOCKIERT durch Equity Curve Filter")
|
||||
return None
|
||||
|
||||
# SCHRITT 2: Signal Analysis
|
||||
signal_info = extended_top_down_v2_adaptive(symbol)
|
||||
if signal_info is None:
|
||||
print("❌ Signal-Analyse fehlgeschlagen")
|
||||
return None
|
||||
|
||||
entry_signal = signal_info["entry_signal"]
|
||||
base_confidence = signal_info["confidence"]
|
||||
adaptive_threshold = signal_info["adaptive_threshold"]
|
||||
|
||||
print(f"\n📊 Base Signal Analysis:")
|
||||
print(f" Direction: {entry_signal}")
|
||||
print(f" Base Confidence: {base_confidence:.1f}%")
|
||||
print(f" Adaptive Threshold: {adaptive_threshold:.1f}%")
|
||||
|
||||
# ==========================================
|
||||
# ⭐ SCHRITT 2.5: REVERSAL CHECK (NEU!)
|
||||
# ==========================================
|
||||
from reversal_integration import check_reversal_risk
|
||||
|
||||
reversal_result = check_reversal_risk(signal_info, symbol)
|
||||
|
||||
print(f"\n🔄 Reversal Check: {reversal_result['action']}")
|
||||
print(f" Score: {reversal_result['reversal_score']}%")
|
||||
print(f" Reason: {reversal_result['reason']}")
|
||||
|
||||
if not reversal_result['should_trade']:
|
||||
print(f"⛔ TRADE BLOCKIERT durch Reversal Detector!")
|
||||
return None
|
||||
|
||||
# Reversal Lot Multiplier kombinieren
|
||||
if reversal_result['lot_multiplier'] < 1.0:
|
||||
lot_multiplier *= reversal_result['lot_multiplier']
|
||||
print(f"📉 Reversal: Lot Multiplier angepasst auf {lot_multiplier:.0%}")
|
||||
# ==========================================
|
||||
|
||||
# ⭐ SCHRITT 3: ENHANCED SIGNAL SCORING (HYBRID 60/40)
|
||||
# ... (Rest des Codes bleibt unverändert)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Kontroll-Befehle
|
||||
|
||||
Nach der Integration kannst du folgende Befehle nutzen:
|
||||
|
||||
```python
|
||||
# Status anzeigen
|
||||
print(get_reversal_status())
|
||||
|
||||
# Reversal Check deaktivieren
|
||||
disable_reversal_check()
|
||||
|
||||
# Reversal Check aktivieren
|
||||
enable_reversal_check()
|
||||
|
||||
# Thresholds anpassen
|
||||
REVERSAL_CONFIG['block_threshold'] = 80 # Weniger strikt
|
||||
REVERSAL_CONFIG['reduce_threshold'] = 60
|
||||
REVERSAL_CONFIG['caution_threshold'] = 40
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Erwartetes Output
|
||||
|
||||
```
|
||||
✅ Session OK: ASIAN
|
||||
✅ Position-Check OK: 0/1
|
||||
📈 Equity Curve: ✅ Equity $108,500.00 > MA $107,200.00 (+1.2%)
|
||||
|
||||
📊 Base Signal Analysis:
|
||||
Direction: 1
|
||||
Base Confidence: 87.5%
|
||||
Adaptive Threshold: 60.0%
|
||||
|
||||
🔄 REVERSAL CHECK (UPTREND):
|
||||
--------------------------------------------------
|
||||
Rsi Divergence : ✅ No divergence
|
||||
Ema Slope Change : ✅ Slope: 0.0045%
|
||||
Volume Spike : ✅ Volume: 1.3x average
|
||||
Candlestick : ✅ No reversal pattern
|
||||
Break Of Structure : ✅ Structure intact
|
||||
--------------------------------------------------
|
||||
✅ Reversal Score: 15% (LOW)
|
||||
Action: ALLOW | Lot Mult: 100%
|
||||
|
||||
🔄 Reversal Check: ALLOW
|
||||
Score: 15%
|
||||
Reason: No significant reversal risk (15%)
|
||||
|
||||
🎯 Calculating Enhanced Signal Score...
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Bei hohem Reversal-Risiko
|
||||
|
||||
```
|
||||
🔄 REVERSAL CHECK (UPTREND):
|
||||
--------------------------------------------------
|
||||
Rsi Divergence : ⚠️ Bearish Divergence: Price HH, RSI LH (RSI diff: 8.5)
|
||||
Strength: 65%
|
||||
Ema Slope Change : ⚠️ Slope weakening: 0.0089% -> 0.0012%
|
||||
Strength: 45%
|
||||
Volume Spike : ⚠️ Volume: 2.8x average (SPIKE!)
|
||||
Strength: 40%
|
||||
Candlestick : ⚠️ Shooting Star: Potential bearish reversal
|
||||
Strength: 60%
|
||||
Break Of Structure : ✅ Structure intact
|
||||
--------------------------------------------------
|
||||
🔴 Reversal Score: 78% (CRITICAL)
|
||||
Action: BLOCK | Lot Mult: 0%
|
||||
|
||||
🔄 Reversal Check: BLOCK
|
||||
Score: 78%
|
||||
Reason: High reversal risk (78% >= 70%)
|
||||
⛔ TRADE BLOCKIERT durch Reversal Detector!
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Dateien
|
||||
|
||||
- `reversal_detector.py` - Haupt-Modul mit allen Algorithmen
|
||||
- `reversal_integration.py` - Integration für den Trading Bot
|
||||
- `REVERSAL_DETECTOR_INTEGRATION.md` - Diese Anleitung
|
||||
Reference in new issue
Block a user