Algorithmic Trading Explained: From Rule to Backtest to Live
An algorithm is just a rule you are no longer allowed to argue with. Everything hard about it happens between writing the rule and trusting the result.
Step 1: write the rule so a machine can read it
"Buy the dip" is not a rule. "Enter on the break of the first 5-minute candle that closes back above a rising 9-EMA while price is above VWAP, stop under the pullback low, target 1.6R" is. If a condition cannot be evaluated from price data alone, it cannot be automated — which is usually a sign it was never measurable by hand either.
Step 2: backtest honestly
- Price fills at what was available, not what you wish. Filling at a quote from eighteen minutes earlier turned one study of ours from a large edge into a small one.
- Test multiple windows. The last 25 sessions, the last 50, the last 100. An edge that only exists in one window is a coincidence.
- Test multiple random seeds. If a change wins on one seed and loses on another, it is noise.
- Include the costs. Commission, slippage, and the trades you would have missed while another position held your slot.
Step 3: the gap between backtest and live
This is where most automated systems quietly fail. The live engine gains a safety rule — a pause after a loss, a filter on choppy tape — that the backtest never modelled. The backtest then says you should be profitable while the account says otherwise, and nobody can explain the difference.
The fix is a parity rule: every rule the live system enforces must also run in the replay, reading the same constant from the same place. When we applied that to our own desk we found three rules that existed only in live trading, and two of them were costing money.
Step 4: the guardrails that make it survivable
- A fixed dollar risk per trade, defined by the distance to the stop.
- A hard daily loss limit that halts new entries.
- A soft brake that halves size once the day is meaningfully red.
- A cap on how many positions can be open at once.
- A profit trail measured from the trade's best point, not its current one, so a winner cannot round-trip.
- A hard cutoff time for new entries before the close.
Does it beat trading by hand?
At following its own rules, always — that is the entire point. At picking setups, only if the setups had an edge to begin with. Automation removes hesitation, revenge trades and size creep; it does not manufacture an edge that was never there.
See the rails running in public on the live desk, or read do AI trading bots work for the checklist to verify any system before you trust it.