Add session filter + auto-toggle, extend trade journal diagnostics

Session filter restricts trades to a UTC hour window (default 07-16,
London + NY) — opt-in via --session-filter, with --session-start /
--session-end overrides. Wired into both the backtester (cheap hour
check next to the regime gate) and live mode (downgrades signal to
NEUTRAL/F when current UTC hour is outside the window).

Auto-toggle (--auto-session-filter) tracks rolling mean pnl_pct over
the last N closed trades; when it falls below threshold, the session
filter activates, releasing once expectancy recovers. Default lookback
10 trades, threshold -0.3%.

Trade dataclass extended with diagnostic fields captured at entry:
entry_hour, entry_dow, ADX, ATR%, market_regime, volatility_regime,
mtf_agreement. These let --journal-csv exports surface loss-pattern
clusters when a window underperforms.

Validated on 2024 trend / 2023 chop / 2026 recent windows. Auto-toggle
preserves ~50% of trend edge while still cutting ~25% of recent-regime
losses — pure regime filter is still best on cumulative, so both
session flags ship default-off.
This commit is contained in:
Harwinder
2026-05-07 18:38:49 -04:00
parent fb1eb5b73f
commit 2e5d66db1b
5 changed files with 139 additions and 1 deletions
+18
View File
@@ -333,6 +333,18 @@ Examples:
help="Gate signals on higher-TF ADX trend confirmation")
parser.add_argument("--regime-min-adx", type=float, default=30.0,
help="Min ADX for regime filter (default 30, requires --regime-filter)")
parser.add_argument("--session-filter", action="store_true",
help="Only trade during a UTC hour window (default 07-16, London + NY)")
parser.add_argument("--session-start", type=int, default=7,
help="Session start hour UTC, inclusive (default 7)")
parser.add_argument("--session-end", type=int, default=16,
help="Session end hour UTC, exclusive (default 16)")
parser.add_argument("--auto-session-filter", action="store_true",
help="Auto-toggle session filter when recent trades show adverse mean pnl%%")
parser.add_argument("--auto-session-lookback", type=int, default=10,
help="Lookback in closed trades for auto-session detection (default 10)")
parser.add_argument("--auto-session-threshold-pct", type=float, default=-0.3,
help="Mean pnl%% threshold below which auto-session activates (default -0.3)")
parser.add_argument("--ablate", action="store_true",
help="Run leave-one-out indicator ablation sweep (parallel)")
@@ -368,6 +380,12 @@ def build_config(args) -> PlatformConfig:
config.backtest.optimize = args.optimize
config.backtest.regime_filter = args.regime_filter
config.backtest.regime_filter_min_adx = args.regime_min_adx
config.backtest.session_filter = args.session_filter
config.backtest.session_start_hour = args.session_start
config.backtest.session_end_hour = args.session_end
config.backtest.auto_session_filter = args.auto_session_filter
config.backtest.auto_session_lookback_trades = args.auto_session_lookback
config.backtest.auto_session_threshold_pct = args.auto_session_threshold_pct
return config