feat: Add session filter to trading check + fix drawdown calculation
Deploy to Windows VPS / deploy (push) Has been cancelled

- Add session check (SCHRITT 0) to enhanced_trading_check_wrapper
- Fix max_drawdown calculation to cap at 100% when equity goes negative
- Add _save_data() after _update_stats() to persist stats
- Add auto-sync scheduler job for demo tracker (every 5 min)
- Fix MT5 trade sync to match entry deals by position_id
- Enable Asian session in session_filter_patch.py

Session config now:
- Asian: ENABLED
- London: BLOCKED
- Overlap: ENABLED
- NY: ENABLED

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
cbazzaandClaude Opus 4.5 committed 2026-01-29 10:47:28 +01:00
1 parent 25b20fa0e2
commit b5b91224df
4 files changed
+8553 -86

No files matched your search

+30 -6
View File
@@ -114,6 +114,9 @@ class DemoTestTracker:
logger.info(f" Days Running: {self._days_running()}")
logger.info("=" * 60)
# Datei sofort erstellen falls sie nicht existiert
self._save_data()
# ==========================================
# TRADE LOGGING
# ==========================================
@@ -280,11 +283,14 @@ class DemoTestTracker:
avg_win = total_wins / len(wins) if wins else 0
avg_loss = total_losses / len(losses) if losses else 0
# Drawdown calculation
# Drawdown calculation (proper method)
# Max drawdown = largest drop from peak (in dollars and percentage)
# Note: Percentage is relative to peak equity at that moment
equity_curve = []
running_equity = 0
peak_equity = 0
max_drawdown = 0
max_drawdown_dollars = 0
max_drawdown_pct = 0
for t in trades:
running_equity += t['profit']
@@ -293,9 +299,23 @@ class DemoTestTracker:
if running_equity > peak_equity:
peak_equity = running_equity
drawdown = (peak_equity - running_equity) / peak_equity if peak_equity > 0 else 0
if drawdown > max_drawdown:
max_drawdown = drawdown
# Calculate drawdown in dollars
current_drawdown_dollars = peak_equity - running_equity
if current_drawdown_dollars > max_drawdown_dollars:
max_drawdown_dollars = current_drawdown_dollars
# Calculate percentage relative to peak
# Only meaningful when peak > 0 and we're still positive
if peak_equity > 0 and running_equity >= 0:
current_drawdown_pct = current_drawdown_dollars / peak_equity
if current_drawdown_pct > max_drawdown_pct:
max_drawdown_pct = current_drawdown_pct
elif peak_equity > 0 and running_equity < 0:
# If equity goes negative, that's 100%+ drawdown
max_drawdown_pct = 1.0 # Cap at 100%
# Final max drawdown (capped at 100%)
max_drawdown = min(max_drawdown_pct, 1.0)
# Session stats
session_stats = defaultdict(lambda: {'trades': 0, 'wins': 0, 'profit': 0})
@@ -327,6 +347,7 @@ class DemoTestTracker:
'avg_loss': avg_loss,
'avg_trade': total_profit / len(trades) if trades else 0,
'max_drawdown': max_drawdown,
'max_drawdown_dollars': max_drawdown_dollars,
'current_equity': running_equity,
'peak_equity': peak_equity,
'sessions_tested': list(session_stats.keys()),
@@ -337,6 +358,9 @@ class DemoTestTracker:
'avg_duration_minutes': sum(t['duration_minutes'] for t in trades) / len(trades) if trades else 0,
}
# Persist updated stats to file
self._save_data()
def get_stats(self) -> Dict:
"""Gibt aktuelle Statistiken zurück"""
self._update_stats()
@@ -469,7 +493,7 @@ class DemoTestTracker:
print(f" Worst Trade: ${stats.get('worst_trade', 0):,.2f}")
print(f"\n📉 RISK METRICS:")
print(f" Max Drawdown: {stats.get('max_drawdown', 0)*100:.1f}%")
print(f" Max Drawdown: {stats.get('max_drawdown', 0)*100:.1f}% (${stats.get('max_drawdown_dollars', 0):,.2f})")
print(f" Current Equity: ${stats.get('current_equity', 0):,.2f}")
print(f" Peak Equity: ${stats.get('peak_equity', 0):,.2f}")