Quant research & trading·Python·Published
MT5 Trading System
This repo is a working MetaTrader 5 bot plus the post-mortem of the session where it lost 82.3% of a demo account in 20 hours 50 minutes, and the post-mortem is the part I actually care about. The engine connects to a live MT5 terminal under Wine, sizes positions with Kelly, trails stops on one-second tick polls, and writes every fill, equity snapshot and risk event to a SQLite ledger, so analysis/trade_forensics.py can reconstruct all 696 closed trades from the bot's own database with no broker statement involved. The headline numbers: equity 565.34 to 100.17, max drawdown 82.32%, win rate 50.43%, average win +1.2978 against average loss -2.6379, which is a realized payoff of b = 0.492 against a config that assumed b = 3.0. At that realized payoff the breakeven win rate was 67.03% and the bot delivered 50.43%, so the gap is the entire loss, and expectancy came out at -0.6531 USD or -0.2401 R per trade. Five causes, all measured: the 0.06% stop sat inside one minute of noise (USOIL's median M1 range was 1.36x the stop), the trailing stop armed after 0.025% and capped the median winner at 0.32x the stop so only one of 351 winners ever reached +3R, spread cost 302.31 USD against a 454.56 USD net loss, lot granularity on a 0.01 grid pushed 55.3% of trades over the 1% risk cap with a worst case of 2.56%, and the daily loss cap fired 58 times while 54% of all trades happened after the first firing. The research harness re-runs the same signal with wider stops and shows SL 0.3% turning three of four symbols positive net with drawdowns of 5-9%, but it ships a random-entry control that lands flat, so I label the entry edge unproven rather than claiming a fix.



- A stop tighter than one bar's median range is not a risk control, it is a donation to the spread: at a 0.06% stop the spread consumed 7% to 25% of the risk budget per round trip, and widening the stop 5x cut that share by 5x.
- Kelly sizing is only as honest as the payoff you feed it; sizing on a configured 1:3 target while the trailing stop structurally capped winners at 0.32R meant the position size was computed from a number the system could never produce.
- A risk breaker that logs a breach and returns control to the loop is an alarm, not a circuit breaker, and the daily cap fired 58 times while 54% of the session's trades still went through.
Scale 0–100: how much this project relied on each skill.