Building a self-learning trading agent that experiments on its own
I taught my AI assistant to run trading experiments 24/7 — change one variable, backtest, compare scores, keep or revert. Here's how the system works and what it's learned so far.
I wanted to know: could I turn my AI assistant into something that doesn't just answer questions, but actually experiments on its own?
Most trading bots just execute. This one learns.
The idea
Instead of writing analysis, my assistant runs experiments — the scientific method, one variable at a time, on a loop. It sleeps, I sleep, but the experiments keep going.
The system is built around a simple loop that runs every 4 hours:
Pick a strategy → change one param → split into train/validation → backtest both → compare scores → KEEP or REVERT → log → repeat
The core engine is locked. The strategies are mutable. The journal persists everything. It's Karpathy-style minimalism applied to quantitative finance.
The architecture

What happened when I let it run
The system ran 3 experiments before hitting the safety gate:
- SMA_Crossover slow SMA 20 → 30: REVERT. The validation score cratered from 0.035 to 0.0.
- SMA_Crossover fast SMA 5 → 10: REVERT. Returns went negative, Sharpe collapsed.
- Same experiment again (a bug): REVERT. Streak hit 3 — auto-pause.
That bug is now fixed. The state persistence didn't track which experiment to run next, so it kept running the same one. Also fixed the IDX stock data gap threshold — Indonesia has way more holidays than the US, the 5% gap threshold was too strict. And silenced the noisy Yahoo Finance 404 errors for delisted pairs like BTC-IDR.
What I learned
The safety mechanisms work — the 3-strike rule properly halts experimentation. The paper trading opens and tracks positions correctly. But the system is only as smart as its strategies, and right now those are basic — SMA crossovers, RSI reversals, Bollinger breakouts. Nothing revolutionary.
What's interesting is watching it run without me. It's like having a junior quant who never sleeps, doesn't complain, and documents every single experiment.
What's next
Now it's running again with a clean streak, testing SMA fast 5 → 15. The cron jobs handle the 24/7 schedule:
- Every 2h: market scan + paper trades
- Every 4h: one experiment
- 07:30 JST: morning briefing
- 20:00 JST: daily report to Obsidian
I want to see how many experiments it takes before something actually works. The system is patient. So am I.
You can find the formal research entry on this site, the full source on GitHub, or the experiment journal in the Trading section of my Obsidian vault.