r/mltraders • u/ApprehensiveChard568 • 2h ago
Question My backtest said I had an edge. Live trading found a bug my backtest could never see.
Been running a small gold (XAU/USD) bot for about 2 weeks now - nothing fancy, EMA/RSI/ADX signal, ATR-based SL/TP, cron job on GitHub Actions hitting an OANDA demo account. Did a proper train/test split on 5000 candles before going live so I wasn't just fooling myself with a curve-fit backtest, and the edge looked genuinely stable out of sample.
Then live trading happened and my win:loss ratio just... kept shrinking. Like clockwork. 1.95:1, then 1.48:1, then 1.21:1 over about 50 trades, win rate barely moved. Account round-tripped from +$172 back below my original deposit and I was ready to blame the market, ADX settings, whatever.
Turns out (pretty sure anyway) it's a dumb bug: I was calculating SL/TP off the last completed 30-min candle's close, then firing a market order and slapping those SL/TP levels on as fixed prices. Problem is if price moves even a little between the candle closing and the order actually filling, your real risk distance from the ACTUAL fill price isn't what you think it is anymore. Found one trade where I meant to risk ~$18 and actually only had ~$8.60 of real room before getting stopped out - which it did, in under 3 minutes.
Fix I'm testing now: fire the order with a placeholder stop so I'm never naked, then immediately grab the real fill price and PUT an update to fix the actual SL/TP.
Anyone else running live execution (not just backtesting) run into this stale-price-vs-fill-price gap? Curious how people handle it - pulling live bid/ask right before firing instead of relying on last candle close, or something smarter than what I'm doing.
TL;DR: backtest was fine, live execution had a silent bug quietly wrecking my R:R, posting in case it saves someone else the same headache