fix: major issues - calibrated confidence, ATR-based filters, smarter exits
Major Issue #1: Confidence Calculation Calibration - Added calculate_confidence() method with weighted scoring - Base 40% + Structure 15% + BOS/CHoCH 12% + FVG 8% + OB 10% + Trend 10% - Capped at 85% (never 100% certain) Major Issue #2: Pullback Filter ATR-based - Replaced hardcoded $2, $1.5 thresholds - Now uses bounce_threshold = 0.15 * ATR - consolidation_threshold = 0.10 * ATR Major Issue #3: Smarter Time-based Exit - Don't cut winners short if profit growing - Check ML agreement before timeout - Extend time to 8h if profit > $10 and growing Major Issue #4: Slippage Validation - Check actual vs expected price after execution - Log warning if slippage > 0.15% of price - Use actual price for position tracking Major Issue #5: Partial Fill Handling - Check if filled volume < requested volume - Log warning with fill ratio - Use actual volume for position tracking Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
0e74f40028
commit
db806b21de
+26
-10
@@ -746,20 +746,36 @@ class SmartRiskManager:
|
||||
elif current_profit > -10:
|
||||
return True, ExitReason.WEEKEND_CLOSE, f"[WEEKEND] Weekend close - small loss ${current_profit:.2f}"
|
||||
|
||||
# === CHECK 8: TIME-BASED EXIT (NEW) ===
|
||||
# Close trades yang stuck terlalu lama tanpa progress
|
||||
# === CHECK 8: SMART TIME-BASED EXIT ===
|
||||
# Don't cut winners short - check profit growth and trend
|
||||
trade_duration_hours = (now - guard.entry_time).total_seconds() / 3600
|
||||
|
||||
# 4+ jam tanpa profit berarti = exit
|
||||
if trade_duration_hours >= 4 and current_profit < 5:
|
||||
if current_profit >= 0:
|
||||
return True, ExitReason.TAKE_PROFIT, f"[TIMEOUT] Closing breakeven/small profit after {trade_duration_hours:.1f}h"
|
||||
elif current_profit > -15:
|
||||
return True, ExitReason.TREND_REVERSAL, f"[TIMEOUT] Closing small loss ${current_profit:.2f} after {trade_duration_hours:.1f}h"
|
||||
# Check if profit is growing (positive momentum = don't exit early)
|
||||
profit_growing = momentum > 0
|
||||
ml_agrees = (
|
||||
(guard.direction == "BUY" and ml_signal == "BUY") or
|
||||
(guard.direction == "SELL" and ml_signal == "SELL")
|
||||
)
|
||||
|
||||
# Maximum 6 jam untuk any trade
|
||||
# 4+ hours: Only exit if stuck (no profit growth)
|
||||
if trade_duration_hours >= 4:
|
||||
if current_profit < 5 and not profit_growing:
|
||||
# Stuck with no growth - exit
|
||||
if current_profit >= 0:
|
||||
return True, ExitReason.TAKE_PROFIT, f"[TIMEOUT] Breakeven + no growth after {trade_duration_hours:.1f}h"
|
||||
elif current_profit > -15:
|
||||
return True, ExitReason.TREND_REVERSAL, f"[TIMEOUT] Small loss ${current_profit:.2f} + no growth after {trade_duration_hours:.1f}h"
|
||||
elif current_profit >= 5 and profit_growing and ml_agrees:
|
||||
# Profitable and growing - extend time (log only)
|
||||
logger.debug(f"[TIME OK] Profit growing +${current_profit:.2f}, extending time (was {trade_duration_hours:.1f}h)")
|
||||
|
||||
# 6+ hours: Exit unless significantly profitable AND still growing
|
||||
if trade_duration_hours >= 6:
|
||||
return True, ExitReason.TREND_REVERSAL, f"[MAX TIME] Position open {trade_duration_hours:.1f}h - forcing close"
|
||||
if current_profit < 10 or not profit_growing:
|
||||
return True, ExitReason.TREND_REVERSAL, f"[MAX TIME] {trade_duration_hours:.1f}h - profit ${current_profit:.2f}"
|
||||
# If profit > $10 and growing, allow up to 8 hours
|
||||
elif trade_duration_hours >= 8:
|
||||
return True, ExitReason.TAKE_PROFIT, f"[MAX TIME] Taking profit ${current_profit:.2f} after {trade_duration_hours:.1f}h"
|
||||
|
||||
# === DEFAULT: HOLD ===
|
||||
status = f"+${current_profit:.2f}" if current_profit > 0 else f"-${abs(current_profit):.2f}"
|
||||
|
||||
Reference in New Issue
Block a user