Create an AI Strategy — the AI builds, tests and fixes

Start at Create an AI Strategy. The AI writes strategy code → your agent backtests it on past data → the AI reads the result and fixes it, in a loop. Watch progress in AI console.

Before you begin — what you need

  • An agent — backtests run on the agent on your own server or PC, from its own candle store. If the agent is off, the job waits.
  • An AI — one of:
  • A connector (Claude, Grok) or our custom GPT — you steer it in chat, inside your chat subscription, at no extra cost.
  • Your own AI key, running automatically — a Claude or OpenAI key, a Gonka broker, or your own Ollama / local worker. Billed to that key per use.
  • The AI you connect can read and edit your strategies but cannot deploy or place real orders.

Running with your own AI key

1. Provider and model — pick from the list when the provider offers one; otherwise type the model.

2. Reviewer AIs (optional) — see below.

3. My standing instructions — see below.

4. What strategy should I build? — words for this job only. Leave it empty and the AI picks symbols and approach.

5. Pick the language the AI writes in (notes, summaries) and start.

  • Keeps going — by default it runs cycle after cycle until you press [Stop]. It stops by itself after 3 cycles in a row with no real progress.
  • Pause and add instructions — from the console you can pause the job or inject an instruction while it runs.
  • Cost estimate — based on the token usage of your own past jobs. With no history it says "unknown".

Reviewer AIs — a different AI checks separately

Pick 0–3 AIs other than the writer, and at the end of every cycle they review the code and its backtest result separately. Only findings whose evidence matches the actual code go back to the writer; when the writer fixes and re-runs, they review again (finding → fix → re-review). Picking the same model as the writer gets a warning — it tends to miss the same mistakes. Reviews are billed to your keys too. The console shows "Cross-review N rounds · last verdict".

My standing instructions — rules for every job

Write them once and they are attached to every job (external AI connectors read the same text). Save several, switch each on or off, or leave them out for one job. The enabled ones are saved into a job when it starts, so editing them later does not change jobs already running.

Example: emergency exit (crash response) — events the data cannot see directly, like quantum risk or a hack, are judged by price instead. The example defaults:

  • Two stages. 8% or more below the 24-hour high (or the last closed bar fell 3× ATR(14) or more) is an ALERT — cut longs by 50% and cancel open buy orders. 15% or more (or 4× ATR(14) or more) is an EMERGENCY — close the remaining longs (shorts are left alone)
  • Never dump everything at market at once. With a large position a single market order eats deep into the book and the loss grows. So it sells with a working order (type:'smart') — no slice larger than 5% of the last closed bar's volume (max 10 slices, 30 s apart), chasing the book and crossing at the deadline so it always finishes
  • no re-entry for at least 7 days; resume only after price recovers (3 closes above the exit price) and volatility normalises (ATR(14) ≤ 1.5× ATR(100))

The numbers are examples, not investment advice. Lower them and it exits on ordinary pullbacks; raise them and it reacts later. Slicing reduces book impact, but price can keep falling while you sell — neither side is free. In periods with no such crash the rule never fires, and the AI reports "never fired — untested". The backtest approximates working orders as one market order, so the slicing effect is not verified by backtest (it is really sliced only in paper and live). ⚠ Split-execution deployments do not support working orders yet — they are dropped (the agent logs a warning), so do not deploy a strategy using this instruction in split mode.

Bulk check of existing strategies

After a platform update (e.g. when ctx.watch declarations arrived), AI checks and fixes every saved strategy. Wizard → Run with my AI key → [Check existing strategies].

1. Pick a scope (running · not discarded · all) and a check, then press [Count targets] — counts per scope and the estimated cost ("unknown" when the model has no price). Default: strategies not marked rejected/archived (running ones always included).

2. Set a cost cap and start. The job pauses when the cap is reached.

3. AI fixes only the flagged strategies. Your agent then runs each fix and the original on the same data and compares fills and metrics (agent v1.281.0+).

  • Identical decisions → saved automatically. The previous code is kept as a revision you can restore.
  • Decisions changed → the AI is told the first differing fill and retries up to 2 times; still different → "needs review".
  • Needs review shows before → after return, MDD and trades, running strategies first. Approve/reject one by one, or [Bulk approve] everything within "return diff ±p pp and MDD worse ≤ q pp" (items with unknown numbers are skipped).
  • Comparison data is picked from the last backtest → saved setup → code header, and each item shows which one was used. None → review.
  • For saved strategies, the comparison backtest appears in the strategy's results as "after check" (the new code's performance).

4. If you edited a strategy during the check, it is not overwritten.

  • This proves the decisions are identical on that data — branches the data never reached are not covered.
  • Running paper/live runs do not change until you press [Redeploy latest code].
  • Comparison jobs do not count toward the daily backtest limit (they do use concurrent slots).

Following progress and results

  • AI console — running jobs, strategies made, finished jobs (with the reason they stopped).
  • Live view — the write · backtest · evaluate · cross-review stages in real time.
  • Strategies open in the studio. Paper and live deployment are always your button — the AI cannot deploy.

Refining in the studio

  • Code | Blocks | Side by side — the buttons above the editor open the code as blocks. Change numbers, operators, indicators and buy/sell, add, move or delete blocks, and watch the code change in Side by side. Code outside the block range (loops, for example) stays in place as a 🔒 locked block.
  • Run settings — a strategy with no saved run settings uses the settings in its code header (exchange, symbols, interval) automatically.
  • Agent version — a strategy that uses a feature an older agent lacks is not deployed to it; you are told which version is needed. Update the agent and deploy again.

Getting an AI API key

  • Claude — console.anthropic.com → Settings → API Keys → Create Key → add a payment method under Billing (prepaid).
  • OpenAI — platform.openai.com → Settings → API keys → Create new secret key → add a payment method under Billing.
  • Gemini — aistudio.google.com/apikey → Create API key. Usable on the free tier without billing, but free-tier inputs and outputs are used to improve Google products and may be reviewed by humans (no free tier in the EEA, UK or Switzerland). Check per-model free limits on AI Studio's usage page.

Paste the key into the wizard — it is verified before saving.

Cost — please read

  • API keys are billed separately from chat subscriptions. Even with Claude Pro or ChatGPT Plus, API usage is charged on top.
  • If you already have a chat subscription, the connector / GPT route is cheaper — no extra cost within your subscription limits.
  • Automatic runs keep going until you press [Stop], so cost grows for as long as it runs; reviewer AIs add more. Set a spending limit (budget cap) in your provider's Billing console.

Security

  • An AI key cannot touch funds — it only incurs AI usage fees. It is a completely different kind of key from exchange API keys.
  • Keys are stored encrypted, shown masked only, and can be deleted anytime (effective immediately).
  • Past test results of generated strategies do not guarantee future results.