feat: add velocity & acceleration tracking to PositionGuard

Enhance PositionGuard in SmartRiskManager with real-time profit velocity
($/s) and acceleration ($/s²) tracking for smarter exit decisions.

Changes:
- Add 7 velocity/acceleration fields to PositionGuard dataclass
- Add _calculate_velocity_acceleration(), _update_stagnation(), get_velocity_summary()
- Add 4 new exit checks: [VEL-EXIT], [DECEL], [VEL-WARN], [STAGNANT]
- Enhance early cut with velocity trigger alternative (vel < -0.4)
- Stricter profit_growing: requires momentum > 0 AND velocity > 0
- Reduce position check interval 10s → 5s for more data points
- Add per-ticket [MOMENTUM] log every 30s in main loop
- Revert unused momentum_tracker integration from position_manager
- Add deprecation note to profit_momentum_tracker.py

All velocity checks respect the 15-minute grace period.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
GifariKemal
2026-02-09 10:45:36 +07:00
co-authored by Claude Opus 4.6
parent 3c4e56ffd2
commit 44e7942718
4 changed files with 514 additions and 14 deletions
+16 -1
View File
@@ -203,7 +203,7 @@ class TradingBot:
self._current_session_multiplier: float = 1.0 # Session lot multiplier
self._is_sydney_session: bool = False # Sydney session flag (needs higher confidence)
self._last_candle_time: Optional[datetime] = None # Track last processed candle
self._position_check_interval: int = 10 # Check positions every N seconds between candles
self._position_check_interval: int = 5 # Check positions every N seconds between candles (more data points for velocity)
# Entry filter tracking for dashboard
self._last_filter_results: list = []
@@ -1944,6 +1944,21 @@ class TradingBot:
regime=regime_state.regime.value if regime_state else "normal",
)
# Per-ticket momentum log (~every 30 seconds)
guard = self.smart_risk._position_guards.get(ticket)
if guard and len(guard.profit_timestamps) >= 2:
now_ts = time.time()
if now_ts - guard.last_momentum_log_time >= 30:
guard.last_momentum_log_time = now_ts
vel_summary = guard.get_velocity_summary()
logger.info(
f"[MOMENTUM] #{ticket} profit=${profit:+.2f} | "
f"vel={vel_summary['velocity']:.4f}$/s | "
f"accel={vel_summary['acceleration']:.4f} | "
f"stag={vel_summary['stagnation_s']:.0f}s | "
f"samples={vel_summary['samples']}"
)
if should_close:
logger.info(f"Smart Close #{ticket}: {reason.value if reason else 'unknown'} - {message}")