fix: stage missing code review fixes (7 files)

Files were edited but not staged in earlier commits:
- adaptive_rhythm_manager.py: mt→mt5, pytz→timezone, get_volatility_level, shutdown()
- check_market_regime.py: ADX_THRESHOLD, Wilder EWM, try/finally, UTC timestamp, sys import
- check_system_status.py: remove duplicate cursor.execute
- drawdown_protection.py: float(inf), persist pause state, DB save_setting, Markdown fix
- performance_analysis.py: KeyError export fix, profit factor, drawdown positive, SQL filter
- performance_analysis_simple.py: fromisoformat, numeric bin sort, profit factor
- trading_dashboard.py: st.rerun(), session_state auto-refresh, pathlib DB path, errors=coerce

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-12 12:25:11 +02:00
co-authored by Claude Sonnet 4.6
parent 5f11d9693c
commit dd2611eaef
7 changed files with 207 additions and 176 deletions
+17 -20
View File
@@ -7,6 +7,7 @@ Umfassende Performance-Auswertung mit nur SQLite
import sqlite3
from datetime import datetime
from collections import defaultdict
from typing import List, Dict
# ==========================================
# DATABASE QUERIES
@@ -14,11 +15,9 @@ from collections import defaultdict
def get_closed_trades(db_path="trading_bot.db", exclude_historical=True):
"""Lade geschlossene Trades"""
conn = sqlite3.connect(db_path)
conn.row_factory = sqlite3.Row
cursor = conn.cursor()
status_filter = "status = 'closed'" if exclude_historical else "status IN ('closed', 'historical')"
query = """
query = f"""
SELECT
ticket, symbol, type, volume,
entry_price, exit_price,
@@ -31,19 +30,15 @@ def get_closed_trades(db_path="trading_bot.db", exclude_historical=True):
profit_pct, rr_ratio,
exit_reason, status
FROM trades
WHERE status = 'closed'
WHERE {status_filter}
ORDER BY exit_time DESC
"""
if exclude_historical:
query += " AND status != 'historical'"
query += " ORDER BY exit_time DESC"
cursor.execute(query)
trades = [dict(row) for row in cursor.fetchall()]
conn.close()
return trades
with sqlite3.connect(db_path) as conn:
conn.row_factory = sqlite3.Row
cursor = conn.cursor()
cursor.execute(query)
return [dict(row) for row in cursor.fetchall()]
# ==========================================
# OVERALL PERFORMANCE
@@ -66,7 +61,9 @@ def calculate_overall_metrics(trades):
avg_win = sum(t['net_profit'] for t in wins) / len(wins) if wins else 0
avg_loss = sum(t['net_profit'] for t in losses) / len(losses) if losses else 0
profit_factor = abs(avg_win / avg_loss) if avg_loss != 0 else 0
gross_profit = sum(t['net_profit'] for t in wins)
gross_loss = abs(sum(t['net_profit'] for t in losses))
profit_factor = round(gross_profit / gross_loss, 2) if gross_loss > 0 else 0
# Calculate drawdown
cumulative = 0
@@ -78,8 +75,8 @@ def calculate_overall_metrics(trades):
if cumulative > max_cumulative:
max_cumulative = cumulative
drawdown = cumulative - max_cumulative
if drawdown < max_drawdown:
max_drawdown = drawdown
if abs(drawdown) > max_drawdown:
max_drawdown = abs(drawdown)
return {
'total_trades': total_trades,
@@ -172,7 +169,7 @@ def analyze_by_confidence(trades):
'avg_profit': avg_profit
})
return sorted(results, key=lambda x: x['confidence_range'])
return sorted(results, key=lambda x: int(x['confidence_range'].split('-')[0]))
# ==========================================
# EXIT REASON ANALYSIS
@@ -215,7 +212,7 @@ def analyze_by_hour(trades):
hours = defaultdict(lambda: {'trades': 0, 'wins': 0, 'profit': 0})
for trade in trades:
hour = int(trade['entry_time'][11:13]) # Extract hour from timestamp
hour = datetime.fromisoformat(trade['entry_time']).hour
hours[hour]['trades'] += 1
hours[hour]['profit'] += trade['net_profit']
if trade['net_profit'] > 0: