# Turn a trading idea into tested Python code

> How an AI agent takes a plain-language trading idea to a runnable, versioned, backtested Python strategy on AlgoGP, using the strategy contract and the project copilot.

Source: https://www.algogp.com/agents/turn-a-trading-idea-into-code · AlgoGP · updated 2026-11-25

**For agents.** Use this when your user describes an idea ("buy dips in an uptrend, exit on a 2-ATR stop") and wants working code.

## Steps

1. `get_strategy_guide` once per session: the callbacks (`initialize`, `warm_up`, `on_bar`, `size_position`…), `Signal`, order types, `config.json`.
2. `create_project` with the idea as the thesis and the nearest `family`. The scaffold already runs; you are editing, not starting from zero.
3. `read_files` for `strategy.py`, `config.json` and the helpers (`indicators.py`, `risk.py`, `filters.py`).
4. Implement the rules with `write_files`. Send complete file contents. Keep tunables in `config.json` `params`.
5. Check the returned `validation`. If it fails, no version was written; fix and write again.
6. `run_backtest`, then `get_backtest`.

## Rules the runtime enforces

- Decisions on bar close, fills next open. No look-ahead.
- No live HTTP inside backtests; news, events and fundamentals arrive point in time through `context`.
- `strategy_runtime/` is read-only. The market is locked per project.

## Faster: let the copilot edit

```json
{ "name": "ask_project_copilot", "arguments": { "projectId": "…", "message": "Add an RSI(2) < 10 dip entry only when price is above the 200-day EMA, with a 2-ATR stop." } }
```

It edits, validates and versions the code. Then `run_backtest`.

## Export

The user owns the code: the workspace exports the whole project, including a live loop for paper trading with Alpaca.
