How to Automate a Trading Strategy
To automate a strategy, start from a rule with no judgement left in it, count the parameters, tune on one half of the history and test once on the other, then run it on a paper account before it touches money. The code is the easy part.
The code is the easy part and almost nobody fails there. What fails is the step before it: deciding which settings to code, using data that has already told you the answer.
Before you start
A rule that already passed a walk-forward test. Automating an untested rule just makes the same mistake faster — how to backtest is the step that comes first.
A platform that runs scripts. Most charting platforms include a scripting language on the free tier, which is enough for everything here.
A paper account. The last step is running it on money that is not real, and skipping it is how a coding error becomes a trading loss.
The steps
1. Rewrite the rule until nothing is left to decide
Every “if it looks like” has to become a comparison between two numbers. This is the whole of algorithmic trading and it is where most attempts stop.
2. Count the parameters
Write down every number the rule contains. That count decides how much of the result you are allowed to believe, so it is recorded before any testing happens.
3. Split the history and tune on one half
Fit as hard as you like on the first half. That is what it is for.
4. Put your costs in the test
A round trip is about 2% of a typical bar here, and across 123 trades it took 67% of the gross. A bot trades more than you do, so this line matters more, not less.
5. Run once on the held-out half
Once. Adjust after seeing it and you have two tuned halves and no test.
6. Run it on paper before it runs on money
Same rule, same size, live data, no capital. This catches the errors a backtest structurally cannot: your fill, your latency, and every place the code disagrees with the rule you thought you wrote.
How to tell it worked
Three conditions, and all three have numbers in them.
The held-out half is positive after costs, and it beats the same number of entries taken on a schedule. Without the control, a positive result is unreadable.
The paper run matches the backtest. Not in profit — in trades. If the bot took 40 trades where the test said 31, the code and the rule are different objects and the difference has to be found before any money is involved.
And the trade count is large enough to mean anything. 25 trades leaves a win rate uncertain by about 20 percentage points either way; roughly 400 pins it to five.
Why more dials make it worse
A grid of 60 settings contains 60 chances for one of them to look good by accident.
That is arithmetic rather than opinion. Every setting produces a result that is part signal and part luck, and searching for the maximum finds the one with the most luck in it just as reliably as the one with the most signal.
Add a third parameter with ten values and the grid is 600. A fourth makes it 6,000. The best result improves every time you add a dial, and none of that improvement is real.
The measured version: the best of 60 settings on the first half of a history made +7.53 and ranked 19th of 60 on the second. Across all 60, the two halves agree at r = +0.38 — some information, and far from a guarantee. That is with two parameters.
What automation actually buys
Consistency — the rule applied identically every time, which is the only condition under which a record means anything.
Attention — it watches everything without deciding it deserves a break.
And no hesitation, which matters most at exactly the moments a person hesitates.
What it does not buy is judgement. Every judgement is still being made; it is made once, in advance, by whoever chose the parameters — and the bot has no way of knowing it was the winner of a search rather than the discovery of an edge.
The original data
Across our study of 24,971 trading videos, only 15 cover automating a strategy. The median one gets 11,143 views, 87% never pass 50,000, and the median length is 34.5 minutes — the longest median of any subject measured anywhere in this glossary.
The corpus carries no description text at all for any of the 15, so this page makes no claim about how the topic is written.
Two things stand out. The field is tiny — 15 videos, against 812 on backtesting and 157 on trading bots. And the median runs over half an hour, which is what a subject looks like when it cannot be demonstrated quickly and honestly.
When it fails
The settings were fitted to the test data
This is the failure, and it is the same one on every page in this section. A result chosen from a grid on the data it is judged against is a search result.
The code and the rule disagree
A bot does exactly what is written, including the part you did not mean. The paper run exists to find that, and it is the step most often skipped.
The conditions changed and it kept going
A rule fitted to a trend keeps firing in a range, paying costs the whole way. Deciding in advance what turns it off is part of writing it, not a later refinement.
It met a gap
The move happens between two bars, so speed is worth nothing and the stop fills where the market opens — the gap trading page has what that costs.
You judged it too early
Sixty trades is not a sample, and a bot losing over sixty is indistinguishable from one that has stopped working. Decide the switch-off rule in advance or you will decide it at the worst moment.
Related
How to backtest a strategy is the step that has to pass before any of this is worth doing.
Algorithmic trading is what “no judgement left in it” actually means.
And do trading bots work has the full grid, the ranks and the correlation between the two halves.
I do not run one, and the reason is not distrust of code. The version of me who picks the settings is the same person whose judgement I would be trying to remove, so all I would have done is move the guessing one step earlier and make it harder to see.
— Michael Whitman
This page is educational, not financial advice. Test every idea on your own charts before risking money.