The framing: "self-learning" here means an offline learning loop, not online/live
reinforcement learning. A bot logs every trade + outcome to a DB; a separate, scheduled process
periodically retrains a model on that accumulated history, which the bot picks up on its next run.
Online RL is data-hungry (thousands of trades to converge) and can develop degenerate strategies
unnoticed — this offline approach is what's actually used at small scale, and is debuggable/reversible.
Phase 1 — Data collection (done): every bot entry/exit logs a full feature snapshot
(RSI, EMA spread, ADX, Bollinger %B, volume ratio, hour of day, which strategy fired) plus the
realized outcome in R-multiples (P&L ÷ amount risked — comparable across trade sizes) into
ai_trades.
Phase 2 — Offline training (done): a GradientBoostingClassifier trained on
features → won/lost, evaluated with a chronological 70/30 walk-forward split, not a random
shuffle — a random split would let the model "see" future market conditions during training,
which is exactly the look-ahead bias that makes a backtested win rate lie. Refuses to train below
200 samples, or score below 20 test-period samples, rather than producing a number that isn't
statistically meaningful yet.
Phase 3 — Shadow mode (not built yet): wire the trained model into a bot at signal-check
time — it computes the same features it already logs, asks the model "would you take this?", and
logs whether it agreed or disagreed with the bot's real rule-based signal. Critically, this
doesn't change what the bot actually does — it's purely observational, so we can see over real
trades whether the model's opinion would've helped before trusting it with anything.
Phase 4 — Gated live filter (not built yet, and shouldn't be until Phase 3 data justifies
it): only once shadow-mode data shows trades the model liked actually won more than the ones
it didn't, let it gate real order placement — "the rule fired AND the model likes the odds" — with
a kill switch that disables it automatically if live performance drops far below backtest.
Guardrails throughout: minimum sample size gates, walk-forward-only
evaluation, shadow mode before any gating, and a kill switch tied to live-vs-backtest divergence —
in that order, never skipped.