Backtesting & rule researchAdvanced#backtest#python#data-quality#hallucination-guard

Log every rule variant you test and judge the best one against the count

Every time an agent tests a version of your rule, a script logs it. The report shows the best result next to how many variants were tried, so a lucky winner out of fifty isn't mistaken for an edge.

How it works

  1. Before a testing session, write the question down: the rule from your own playbook you're testing on your own data, the one variant you expect to keep, and the measure you'll judge it by (for example average R per trade after costs). Decide this before you see any result.
  2. Wrap your backtest script so every run appends one row to a trial log: date, rule version, every parameter value, sample period, trade count and the headline measure. The agent may only run tests through the wrapper.
  3. Count variants honestly. A changed lookback, an added filter, a different period or a rerun after a bug fix each count as a new trial, including runs you abandoned halfway.
  4. When you ask for a summary, the agent reports the best variant together with the number of trials, the spread of results across all trials and how the median variant did, never the best one alone.
  5. The script marks any best result that rests on fewer trades than your minimum, or that sits far above variants with neighbouring parameter values (a lone spike rather than a plateau).
  6. A variant you want to keep gets one run on a fresh, untouched period, with the trial count written next to it in your journal. If it fails there, that goes in the log too.

Copy-paste prompt

You help me test my own written trading rules on my own data. You do not give trading advice, you never suggest rules, markets or securities, and you never present one test result without its context.
Inputs: the trial log {{trial_log_csv}} (date, rule_version, parameters, period, trade_count, metric) and my pre-registered question {{question_note}} (the rule, the variant I expect to keep, the metric and my minimum trade count {{min_trades}}).
1. Run every backtest only through {{wrapped_script}}, so each run is appended to the trial log. If anything was run outside it, say so first.
2. Report: total trials so far, the best variant and its metric, the median variant's metric, and the share of variants with a metric above zero.
3. Flag the best variant if its trade count is below {{min_trades}}, or if variants with neighbouring parameter values score much worse.
4. Compare the best variant with the one I said in advance I expected to keep.
5. Draft the summary as one journal line that always includes the trial count, show it to me as a diff, and append it to my journal only after I confirm. Never write "this works" or "this has an edge".
Every number comes from the script output, not from you.

Guardrails

  • The wrapper appends a trial-log row on every run that goes through it. Instruct the agent to use only that wrapper. Claude Code and Codex will not block a command that skips it, so treat a missing row or a deleted session as a failed log, not as enforcement.
  • The best result is never reported without the number of trials and the median result next to it.
  • Tests cover your own written rule on your own data. No rule suggestions, scans or trade lists.
  • A held-out period is used once per kept variant. Looking at it again makes it part of the search.
  • Read-only on price files; no broker connection. The only writes are the script's own trial-log rows and one summary line in your journal, which the agent shows you as a diff and appends only after you confirm.

What can go wrong

The trial count is only honest if abandoned runs go in too, and the temptation is to delete the rows from a session that "had a bug", which is exactly when the most variants get tried. The held-out period is the second trap: look at it twice and it has become part of the search. A trial count also isn't a significance test by itself. It's a warning label, so treat a best-of-fifty result as a reason to gather more data, not as an answer.

Why it helps

An agent makes testing cheap: it can try forty versions of your rule before lunch. That's useful right up to the moment you look only at the best one. With enough tries, some version will look good by luck, and nothing in a single result tells you whether it was luck. The trial log puts the missing context back: how many versions you tried, how the typical one did, and whether the winner sits on a broad plateau or a lone spike. Writing the question down first stops the goalposts moving once the numbers come in.

How it fits with other entries

The quick rule backtest (aft-0018) and the paper-vs-practice comparison (aft-0030) are ways to test a rule. This entry is the bookkeeping around them, so their results come with a trial count. The prove-it-runs check (aft-0036) makes sure the script behind a trial is right before its result counts.

Where this comes from

A public post by @slarmxl on X: an agent that tests hundreds of ideas will "discover" some that are only noise, and published finance research has had to raise its bar for this reason. A reply by @valeretn makes the same point about adjusting for the number of variations tried. The research paper linked below is the background on raising the bar. The trial log, the pre-registered question and the reporting rule are ours.

Source and references

Based on a public post by @slarmxl on X explaining that an agent able to test many trading ideas quickly will find some that look good by chance alone, and pointing to the multiple-testing problem in finance research. The trial log, the pre-registered question and the report format are our adaptation, in our own words.

Original: Slarmxl on x

Spotted an error, or want your post removed? Email hello@agentsfortraders.com.

Educational content only. Not investment advice or a personal recommendation. No tickers, signals or trade alerts. Trading involves risk of loss.

Conteúdo exclusivamente educativo. Não constitui aconselhamento nem recomendação de investimento. Sem tickers, sinais ou alertas de negociação. Negociar envolve risco de perda.

Related use cases