Files
Place-Order-Trading-Bot/diagnose_no_trades.py
T

175 lines
5.8 KiB
Python
Raw Normal View History

2025-12-16 22:02:15 +01:00
#!/usr/bin/env python3
"""
🔍 Diagnose: Why No Trades Are Being Executed
Checks all possible blocking reasons
"""
import sqlite3
from datetime import datetime, timedelta
DB_PATH = "trading_bot.db"
def diagnose_no_trades():
"""Comprehensive diagnosis of why no trades"""
print("=" * 70)
print("🔍 DIAGNOSE: WHY NO TRADES?")
print("=" * 70)
problems_found = []
# 1. Check Database
print("\n1️⃣ CHECKING DATABASE...")
try:
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
# Consecutive losses
cursor.execute("""
SELECT net_profit
FROM trades
WHERE status = 'closed'
ORDER BY exit_time DESC
LIMIT 20
""")
trades = cursor.fetchall()
consecutive_losses = 0
for trade in trades:
if trade[0] < 0:
consecutive_losses += 1
else:
break
print(f" Consecutive Losses: {consecutive_losses}")
if consecutive_losses >= 5:
problems_found.append(f"🚨 DRAWDOWN PROTECTION: {consecutive_losses} consecutive losses (limit: 5)")
print(f" 🚨 BLOCKED: {consecutive_losses} ≥ 5")
print(" 💡 Solution: Wait 24h cooldown OR run reset_consecutive_losses.py")
else:
print(f" ✅ OK: {consecutive_losses} < 5")
# Check recent trades
cursor.execute("""
SELECT COUNT(*) FROM trades
WHERE entry_time >= datetime('now', '-1 day')
""")
recent_trades = cursor.fetchone()[0]
print(f" Recent Trades (24h): {recent_trades}")
# Check open positions
cursor.execute("""
SELECT COUNT(*) FROM trades WHERE status = 'open'
""")
open_positions = cursor.fetchone()[0]
print(f" Open Positions: {open_positions}")
conn.close()
except Exception as e:
print(f" ❌ Database Error: {e}")
problems_found.append("❌ Database connection issue")
# 2. Check Time/Session
print("\n2️⃣ CHECKING TRADING SESSION...")
now = datetime.utcnow()
hour = now.hour
# NY Session: 13:00-22:00 UTC
# Asian Session: 23:00-08:00 UTC
in_ny_session = 13 <= hour < 22
in_asian_session = hour >= 23 or hour < 8
print(f" Current Time (UTC): {now.strftime('%H:%M:%S')}")
print(f" NY Session (13:00-22:00): {'✅ ACTIVE' if in_ny_session else '❌ INACTIVE'}")
print(f" Asian Session (23:00-08:00): {'✅ ACTIVE' if in_asian_session else '❌ INACTIVE'}")
if not in_ny_session and not in_asian_session:
problems_found.append("⏰ OUTSIDE TRADING SESSIONS (London blocked)")
print(" 🚨 London Session is BLOCKED (break-even performance)")
print(" 💡 Wait for NY (13:00 UTC) or Asian (23:00 UTC) session")
else:
print(" ✅ Currently in active trading session")
# 3. Possible Ranging Market
print("\n3️⃣ POSSIBLE BLOCKING REASONS...")
print(" 📊 Ranging Filter:")
print(" If ADX < 25 → Trades are BLOCKED")
print(" This is EXPECTED and PROTECTS you!")
print(" 💡 Run show_current_regime() in notebook to check")
print("\n 📉 Low Confidence:")
print(" If confidence < 70% → Trade might be skipped")
print(" 💡 Check confidence in signal")
print("\n 💰 Risk Limits:")
print(" If ATR too small → Trade skipped")
print(" If position size < minimum → Trade skipped")
print("\n 🔒 Max Positions:")
print(" If already 1 position open → No new trades")
print(f" Current open: {open_positions}")
# 4. Summary
print("\n" + "=" * 70)
print("📋 DIAGNOSIS SUMMARY")
print("=" * 70)
if problems_found:
print("\n🚨 PROBLEMS FOUND:")
for i, problem in enumerate(problems_found, 1):
print(f" {i}. {problem}")
else:
print("\n✅ NO BLOCKING ISSUES FOUND")
print("\n💡 MOST LIKELY REASONS:")
print(" 1. 🛑 Ranging Market (ADX < 25)")
print(" → This is GOOD! Filter is protecting you")
print(" → Check with: show_current_regime()")
print("\n 2. 📉 Low Confidence Signal")
print(" → Signal quality below threshold")
print(" → This is GOOD! Only high-quality trades")
print("\n 3. ⏰ Waiting for Better Entry")
print(" → Bot is patient, waits for optimal conditions")
print(" → This is GOOD! Quality over quantity")
# 5. Action Items
print("\n" + "=" * 70)
print("🎯 ACTION ITEMS")
print("=" * 70)
print("\n1. Check Current Market Regime:")
print(" In Jupyter Notebook run:")
print(" → show_current_regime()")
print("\n2. Check if Scheduler is Running:")
print(" In Jupyter Notebook run:")
print(" → scheduler.get_jobs()")
print(" → Should show 5-6 active jobs")
print("\n3. Check Last Trading Check:")
print(" Look for these messages in notebook output:")
print(" → '🛑 TRADE BLOCKIERT: Ranging Market!' (expected)")
print(" → '✅ REGIME CHECK PASSED: TRENDING' (good for trading)")
print("\n4. Verify Ranging Filter is Active:")
print(" In Jupyter Notebook run:")
print(" → print(execute_trade_v2_adaptive)")
print(" → Should show: 'execute_trade_v2_adaptive_with_ranging_filter'")
print("\n" + "=" * 70)
print("💡 REMEMBER: No trades might be GOOD!")
print("=" * 70)
print("\nThe Ranging Filter BLOCKS unprofitable ranging markets.")
print("This is PROTECTING you from losses!")
print("\n✅ Patience = Profitability")
print("✅ Quality trades > Quantity of trades")
print("✅ Wait for ADX > 25 (trending market)")
print("\n")
if __name__ == "__main__":
diagnose_no_trades()