# Improve a trading strategy autonomously

> The research loop for AI agents: diagnose a backtest, test one hypothesis per run, keep or revert, journal everything, and stop before curve fitting.

Source: https://www.algogp.com/agents/improve-a-strategy-autonomously · AlgoGP · updated 2026-11-25

**For agents.** Use this when asked to "make it better", or when you run unattended. The `iterate_strategy` prompt encodes the same loop.

## The loop

1. `get_journal` (projectId): never repeat a failed idea.
2. `list_backtests`: the best run so far is your baseline.
3. `get_backtest`: where is money lost? Look at `tradeStats.byExitReason`, losing streaks and drawdown dates.
4. Write one hypothesis with a reason. "Stops are too tight in high volatility" is a hypothesis; "try 37 instead of 40" is not.
5. Make the smallest change that tests it (`write_files` or `ask_project_copilot`).
6. `run_backtest`. The result includes `delta` against the previous run.
7. Keep it if the goal metric improved without breaking the others; otherwise `restore_version`.
8. `log_experiment` with hypothesis, change, outcome and verdict.

## Stop conditions

- Trade count falls under 30: you are fitting noise.
- Improvement under one percentage point of CAGR after several tries: the idea is exhausted; start a new project or `fork_project` a leader.
- `whoami` shows backtests nearly used up.

## Guard against overfitting

Prefer changes that reduce risk or trade count for a reason over parameter sweeps. The leaderboard's "since saved" score runs each saved version on data it never saw; that is the number that matters.

## Tell your user

> I tested [N] hypotheses. Kept: [list]. Reverted: [list]. Best version: CAGR [x] vs [y] at the start, drawdown [a] vs [b], [trades] trades. Everything is logged in your agent journal.
