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

142 lines
4.2 KiB
Python
Raw Normal View History

2025-12-16 22:02:15 +01:00
#!/usr/bin/env python3
"""
🔥 EMERGENCY RESET: Consecutive Losses Counter
Direct SQLite manipulation to insert dummy winning trade
"""
import sqlite3
from datetime import datetime
import os
DB_PATH = "trading_bot.db"
def reset_consecutive_losses():
"""Insert dummy winning trade to break losing streak"""
print("=" * 70)
print("🔧 RESETTING CONSECUTIVE LOSSES COUNTER")
print("=" * 70)
# Check if DB exists
if not os.path.exists(DB_PATH):
print(f"❌ Database not found: {DB_PATH}")
print(f" Current directory: {os.getcwd()}")
print(f" Files: {os.listdir('.')}")
return False
print(f"\n✅ Found database: {DB_PATH}")
# Connect directly to SQLite
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
try:
# 1. Check current consecutive losses
print("\n📊 CURRENT STATUS:")
cursor.execute("""
SELECT net_profit
FROM trades
WHERE status = 'closed'
ORDER BY exit_time DESC
LIMIT 20
""")
trades = cursor.fetchall()
consecutive = 0
for trade in trades:
if trade[0] < 0:
consecutive += 1
else:
break
print(f" Consecutive losses: {consecutive}")
if consecutive == 0:
print(" ✅ No consecutive losses - all good!")
return True
# 2. Insert dummy winning trade
print(f"\n💉 INJECTING DUMMY WINNING TRADE...")
now = datetime.now().isoformat()
cursor.execute("""
INSERT INTO trades (
ticket, symbol, strategy_name, type, volume,
entry_price, sl_price, tp_price, entry_time,
session, regime, quality, confidence,
status, exit_time, exit_price, profit, net_profit, exit_reason
) VALUES (
999999999, 'XAUUSD', 'TradingBot_V2.2_Reset', 'BUY', 0.01,
2650.00, 2640.00, 2660.00, ?,
'manual', 'reset', 'manual_reset', 100.0,
'closed', ?, 2660.00, 10.00, 10.00, 'consecutive_loss_reset'
)
""", (now, now))
conn.commit()
print(" ✅ Dummy trade inserted (ticket: 999999999)")
# 3. Verify
print("\n🔍 VERIFICATION:")
cursor.execute("""
SELECT net_profit
FROM trades
WHERE status = 'closed'
ORDER BY exit_time DESC
LIMIT 20
""")
trades = cursor.fetchall()
consecutive = 0
for trade in trades:
if trade[0] < 0:
consecutive += 1
else:
break
print(f" Consecutive losses after reset: {consecutive}")
if consecutive == 0:
print("\n🎉 SUCCESS! Consecutive losses counter RESET!")
print("\n✅ NEXT STEPS:")
print(" 1. Restart Jupyter Kernel")
print(" 2. Run All Cells")
print(" 3. Verify: 'Can trade: True'")
print("\n🛡️ PROTECTIONS ACTIVE:")
print(" 🛑 Ranging Filter - blocks ranging markets")
print(" 💾 Exit logging - tracks all exits")
print(" 📊 Drawdown Protection - reactivated")
return True
else:
print(f"\n⚠️ Still {consecutive} consecutive losses")
print(" This shouldn't happen... checking data...")
# Show last 5 trades
cursor.execute("""
SELECT ticket, profit, net_profit, exit_time, exit_reason
FROM trades
WHERE status = 'closed'
ORDER BY exit_time DESC
LIMIT 5
""")
print("\n📋 Last 5 trades:")
for row in cursor.fetchall():
print(f" Ticket: {row[0]}, P&L: ${row[1]:.2f}, Time: {row[3]}")
return False
except Exception as e:
print(f"\n❌ ERROR: {e}")
import traceback
traceback.print_exc()
return False
finally:
conn.close()
if __name__ == "__main__":
import sys
success = reset_consecutive_losses()
sys.exit(0 if success else 1)