docs › Strategy factory
Strategy factory
Your own Claude reads how every strategy did and writes one new paper strategy candidate per run, with its reasons. The factory tests it on days the model never saw, queues a paper forward test, and retires it if the forward test fails. Turn strategies on and off by asking the in-app chat. Paper only; candidates are not edges; not financial advice.
The strategy factory automates the loop you would otherwise do by hand: look at how every strategy did, think about why, write a new one, test it honestly, keep what holds up and drop what does not. It runs on a schedule (once a day by default) and makes at most one new paper strategy candidate per run.
Read this first. A candidate is not an edge. The factory works from the same limited recorded history as everything else, the model can be wrong, and most candidates will fail their tests. Every result is paper and simulated, with modelled fills. Nothing the factory makes trades real money, and nothing it makes is promoted without you.
What one run does#
- Gathers the evidence (read only). For every strategy you have (the presets, your own and earlier candidates): on your recorded history, each candidate coin entered at a fixed $20, the number of entries, the mean result per entry after modelled costs, its 95% range, the mean if costs were twice as high, the mean without the three best entries, and the rug rate. It adds each strategy's forward-test result and paper ledger if it has one, and the factory's own lessons so far (
lessons.md: what failed, what held up). - Asks your own Claude (the same
claudecommand the analyst uses, no tools, a hard spending cap per call) for one new strategy: changes to the entry rules and exits of one strategy, optionally borrowing from others, with a written reason for every rule, what it expects to fail on and what it changes versus its parents. It may also suggest retiring a bad strategy; that stays a suggestion. - Checks the reply before anything is saved: A rejected reply is logged with its reasons; the next attempt is told why. The number of attempts per run is capped.
- every number it cites must be in the evidence it was given, with the same value; a reply with an invented number is rejected;
- it may change entry rules and exits only: never sizing, risk limits, caps, the bankroll, the fill model, the mode, or a safety check's on/off switch;
- it must validate (
dexterm autotrade validate), and its rules must not already exist (same rules hash) or be a near copy of an existing strategy.
- Tests it on days the model never saw. The newest days (3 by default) are held back from the evidence. The candidate is backtested on them once: entries, mean per entry, 95% range, at 2x costs, without the top 3, rug rate, and a plain verdict. That result is written next to the strategy (
generated/<id>/report.jsonandrationale.md) and counts as its backtest on the ladder. - Queues a paper forward test (live data, its own paper bankroll, 72 hours or 200 closed trades, whichever comes first). Only one runs at a time by default. A candidate whose whole held-out 95% range is below zero (at least 20 entries) cannot pass the forward bar on that evidence: it is retired at once (kept on disk, with the reason) and does not take a forward slot.
factory config set forward.skipHeldOutLosers falsequeues it anyway. - Judges finished forward tests on the next run. A candidate whose forward test lost, ended early, or made fewer than 10 closed trades is retired: kept on disk with its report and the reason, never deleted. One that ended above zero is marked forward-passed, which still only means "a candidate": the bar for calling any strategy good (at least 100 closed forward entries, the whole 95% range above zero, still above zero at twice the costs) is far higher, and promotion to always-on is always your decision.
Generated strategies are always paper and decide mechanically (no model calls while they run), so the backtest and the forward test measure the same thing. They are tagged GENERATED on the Q screen and everywhere else.
Run it, see it, stop it#
dexterm autotrade generate # one run now (same as: dexterm autotrade factory run)
dexterm autotrade generate --stub # a dry run with a stub instead of Claude: no spend
dexterm autotrade factory run --focus "try a sell ladder on older coins" # tell one run what to try (one line, 500 characters at most)
dexterm autotrade factory status # last run, spend today, caps, every candidate and its stage
dexterm autotrade factory show <id> # why a candidate was made, and its held-out result
dexterm autotrade factory retire <id> # retire a candidate yourself
dexterm autotrade factory lessons # what the factory has learned so far
dexterm autotrade factory stop # writes FACTORY-STOP: nothing runs until you resume
dexterm autotrade factory resume
To run it on a schedule:
dexterm autotrade factory install # shows the scheduler file it would write; writes it, does not load it
dexterm autotrade factory install --load # writes and loads it
dexterm autotrade factory uninstall # removes exactly what install wrote
On macOS this is a LaunchAgent, on Linux a systemd user timer; the file is generated, never hand-edited. The default slot is 04:10 local time, after the nightly tuning job. An interval that divides the day runs at fixed slots counted from that time (factory config set intervalHours 4 = 00:10, 04:10, 08:10, 12:10, 16:10, 20:10). A scheduled run skips itself while another run holds the lock or the machine has less than minFreeMemMb (4096 MB) of memory available; a run you start by hand does not check memory. Only scheduled runs count for the cadence, so a run by hand never makes the next slot skip. On Windows, run dexterm autotrade factory run --scheduled from Task Scheduler yourself.
Ask the chat#
In the in-app chat you can say, in plain words:
- "list my strategies", "which are on?", "how is ss-s2 doing?"
- "show me the newest generated strategy and why it was made"
- "turn ss-s2 off", "turn it back on"
- "retire gen-1105-a3f2"
- "pause the factory", "resume the factory", "run the factory now"
Every change is shown to you first, for example: turn ss-s2 off: its always-on PAPER entry is disabled, and the running one takes no new paper entries from its next tick; open bags are kept and keep their exits. It happens only when you reply "yes" (or the code it shows) in your next message; "no" cancels. The model cannot confirm for you, and a change offered more than 10 minutes ago expires.
On and off is the paper always-on switch of a strategy that is already on your always-on list (autotrade.json). A strategy that is not on the list gets there only through the promotion flow, which you apply with a key.
What the chat cannot do: switch anything to real mode, arm it, change a cap, a limit or a bankroll, or anything that signs or sends. Ask for it and the chat says no and points you to dexterm autotrade promote <id> --to real and dexterm autotrade signal arm <id> on your own terminal (real mode). The Telegram bot can show the same read-only views; it cannot change anything.
Drive the factory from your agent#
Any agent connected to dexterm's MCP server (Claude Code, the stream agent, your own) can work the same loop as the chat, on paper only. It reads, it can offer a candidate of its own, and it can pause the factory; anything that changes your always-on list waits for you.
Reads: factory_status (paused or not, the last and next run, candidates by stage, every cap with what is in use, proposals waiting for you), factory_candidates, factory_why (one candidate's parents, the evidence numbers it cited, the lessons it saw), factory_lessons (lines from the held-out days hidden), factory_evidence (the table the factory's own analyst was shown), strategy_compare_lab (backtest, held-out, forward test and the running lab account side by side). Their text is untrusted data, framed as such.
A worked example. The agent:
- calls
factory_status: not paused, 2 of 5 candidates active, 1 of 3 Claude calls used today; - reads
factory_lessonsandfactory_evidence, and picks a base from the table, say row S2; - calls
factory_offer_candidatewithbaseandparentsfrom the table, aname, ops on/entryand/exits(or a whole strategy file), a reason for every rule, and the numbers it relies on as citations, for example{"ref": "S2.mean2xPct", "value": -8.0}; - gets back an offer id (or the reasons it was refused), and later sees it in
factory_candidatesasGENERATED, made bymcp:<its name>, with its held-out line and forward-test progress.
An offer goes through the same gate as the factory's own output: the reply shape, the rule policy (no safety switch, no sizing, carry or re-entry change), the strategy validator, every cited number checked against the evidence it was shown (a number that is not there gets it refused), the wording check, and the duplicate checks. A passing offer waits in the factory inbox (at most 3, 6 a day). The next factory run, or factory_run_now with analyst: false (inbox only: no Claude call, nothing spent), stores it as a paper candidate, tests it once on held-out days the evidence did not include, and queues a paper forward test under your caps. The agent cannot set its bankroll, caps, mode or budget, and cannot promote it.
Controls:
| tool | what it does | how to undo it |
|---|---|---|
factory_pause | writes the agent's own pause marker (AGENT-PAUSE); no run starts | factory_resume, or dexterm autotrade factory resume |
factory_resume | lifts the agent's pause only; your FACTORY-STOP stays, and a resume proposal waits for you | factory_pause |
factory_run_now | starts one run (one at a time, 30 minutes apart, 4 a day); every cap applies inside it | strategy_retire on what it made |
strategy_retire | retires a candidate the factory generated (never a preset or one of yours), with a reason; if you put that candidate on your always-on list, it is only a proposal (it would turn the entry off) | dexterm autotrade factory unretire <id> |
strategy_enable / strategy_disable | only propose the paper always-on switch; autotrade.json is your file | not applied until you confirm |
You apply an agent's proposal with dexterm autotrade factory confirm <code> (or --cancel), or by writing its code in the in-app chat ("confirm C1A2B3C"; a bare "yes" is not enough for an agent's proposal). dexterm autotrade factory pending lists them; they expire after 24 hours. The in-app chat itself keeps using its own preview-and-confirm tool.
What no agent tool can do: sign or send anything, set a mode, change a bankroll, a cap or a Claude budget, raise its own limits, promote past paper (promotion stays strategy_promote_propose and your key), delete or overwrite a preset or one of your strategies, write outside the factory and strategy files, or remove FACTORY-STOP.
The caps#
Every cap stops the run and says which cap it hit; none of them loosens anything else. Defaults, all editable with dexterm autotrade factory config set KEY VALUE:
| setting | default | what it limits |
|---|---|---|
maxCandidatesPerRun | 1 | new candidates per run |
maxAttemptsPerRun | 3 | replies tried per run before it gives up |
maxActiveGenerated | 5 | candidates not yet retired; at the cap nothing new is made |
maxConcurrentForward | 1 | forward tests of candidates at once |
maxCallsPerRun / maxCallsPerDay | 3 / 3 | calls to your Claude |
maxUsdPerCall / maxUsdPerRun / maxUsdPerDay | $1 / $2 / $2 | what those calls may cost (the CLI's own spending cap per call; a call that times out or reports no cost counts as the full per-call cap) |
maxDiskMb | 50 | disk for the factory's files |
evidenceDays / heldOutDays | 10 / 3 | history the model sees / newest days held back for the test |
intervalHours / at | 24 / 04:10 | how often it runs, and when |
minFreeMemMb | 4096 | a scheduled run skips itself under this much available memory (0 = off) |
forward.skipHeldOutLosers | true | retire a candidate whose whole held-out range is below zero instead of forward-testing it |
Values above a hard ceiling (for example more than $20 a day or 3 candidates a run) are refused.
Where it should run#
On the machine that runs the recorder (its history is what the factory reads; it opens it read-only). A run on ten days of history reads every coin of those days into memory and replays each strategy twice: expect a few minutes of one CPU core and up to about 2 GB of memory, once a day, at low priority. Do not schedule it on a machine that is streaming or recording video at the same time.
Files#
Everything is under ~/.dexterm/autotrade/factory/ (or $DEXTERM_HOME): factory.json (your settings), generated/<id>/ (report, rationale, strategy copy), lessons.md, runs.jsonl (one line per run), spend.jsonl (one line per Claude call), FACTORY-STOP, AGENT-PAUSE (an agent's pause), evidence.json (what an agent may cite), inbox/ (agent offers), pending/ (changes waiting for your confirm). The candidates themselves are ordinary strategy files in ~/.dexterm/strategies/.