Automated Trading: Build the Kill Switch
Automated trading is the operational side of running a strategy without a person at the keyboard: hosting it, monitoring it, and stopping it safely. The hard part is rarely the signal — it is execution, and a stop that only ever existed inside a script that is no longer running.
The interesting part of automation takes a weekend; the rest never finishes. Once a rule runs without you, the subject stops being the rule and becomes uptime, orders, logs and the switch that stops it.
How it works
A program holds the decision instead of you. It reads prices on a schedule, applies conditions somebody wrote down, and sends orders without asking. What those conditions should be is algo trading and systematic trading.
A live system has three parts, and they are nothing like the same size. Generating the signal is small and interesting. Execution and monitoring are most of the work and almost none of the published material.
It also needs somewhere to live that never sleeps. A machine that hibernates or loses its connection at three in the morning is not a host; the requirement is continuous uptime and a stable link.
The operator’s job
Execution is where home-built systems fail, and the modes are specific. An order sent twice after a timeout. One rejected for insufficient margin and never retried. A partial fill treated as a full one. A position lost after a restart.
A dropped connection with a position open is the real risk. Not a bad signal — an order that was sent twice, or a stop that only ever existed inside a script that is no longer running.
So the kill switch comes before the strategy. One tested action that flattens every position and stops the program. Build it while nothing is at stake, and know how to trigger it from a phone.
Without logs you cannot tell what it did. Record every decision, every order sent, every response received. Otherwise a bad week is unattributable — strategy or bug, and you are guessing.
Live results drift from the test, and the drift is a number. Compare live fills against what the backtesting run assumed, and keep the difference in a trading journal. Almost nobody records it.
In practice
Automation multiplies trade count, and cost scales with count. A rule you traded twice a week by hand becomes one that fires whenever its condition is met, at any hour, without fatigue.
A thin market is where slippage stops being small. Falling volume is the condition your fills degrade in, and a program does not notice the book thinning under it.
A slower system is far easier to automate safely. Longer bars mean fewer orders, more tolerance for a late fill, and a bid-ask spread worth a smaller share of the move.
An opening gap is the event the code never saw in testing. Price arrives past your level with nothing in between, so an order expecting a fill there gets one somewhere else.
A resting order at the broker is the only stop loss that survives your machine. Send it as the entry fills, and size it as risk management rather than as a setting.
Every round trip costs 2% of a median bar, and 45% of the smallest one. On 15 of this site’s 576 bars it exceeds a tenth of the whole range.
Going live in stages
Nothing goes from a test straight to real size. Run it on a demonstration account first, long enough to see it restart, reconnect and meet a session it did not expect. Judge that stage on whether the orders match the intent.
Then go live at the smallest size the broker allows. Real money changes the answer, because queue position, rejections and fill prices only exist once the order is real.
Then compare the live record against the test, trade by trade. Same signals, different fills — the gap is your drift, and the only honest check on whether forward testing agreed with history.
Only then increase size. A large drift is not a sizing problem but an execution problem, and size multiplies the wrong number.
What automated trading is not
It is not a strategy. The rules are systematic trading; automation only executes them.
It is not an expert advisor you switch on and leave. Somebody still hosts it, watches it and stops it.
It is not evidence the edge exists. That belongs to backtesting and forward testing.
It is not hands-off. The decision moves; it does not disappear.
When it fails
It keeps trading in a trading range when a person would stop. Direction runs here average 2.01 bars across 286 runs, longest 11: the next bar usually disagrees with the last.
The host went down and nobody was told. A machine that sleeps holds a position with no manager, and you find out hours later.
A restart lost the position. The program reconnects, sees no open state in its own memory, and either does nothing or opens a second position on top of the first.
The version that went live was the tuned one. Overfitting survives the move to production intact, because nothing about running a strategy tests whether it was fitted to its own history.
Bar sizes are not stable, so cost is not either. The tenth percentile bar range is 0.17 and the ninetieth 1.101, a ratio of 6.5 — trivial in one regime, material in another.
The operator switched it off at the bottom. Automation moves the decision rather than removing it, and the one that remains — whether to stop the system — arrives during a drawdown.
The original data
research/broker-coverage.json scans the 31,760 trading and investing videos in
research/search-study-corpus.jsonl. “Automated trading” appears in 43 titles, median 11,143 views
across 21 channels, maximum 149,372. “Trading bot” takes 109 videos at a 9,739 median;
“algorithmic trading” 97 at 5,184; “expert advisor” 9 at 11,637.
“Backtest” appears in 812 titles from 400 channels, median 2,115 views. “Python trading” appears in four, median 1,360, and “risk of ruin” in none at all.
Roughly 250 videos cover the automation terms and 812 cover backtesting, against zero on risk of ruin and four on the programming side. The published material is about producing a strategy, not operating one. The operational half — hosting, logging, resting stops, restarts — is missing, and it is where live systems break.
Then the cost, measured in research/series-measurements.json by site/measure_series.py. A
round trip is 2% of a median bar and 45% of the smallest, so trading ten times more often needs ten
times the edge to stand still. Build the kill switch and the logs before the strategy, and never run
live what you have not already stopped on purpose.
Related
Algo trading is the design half — writing a rule precisely enough that a machine can follow it.
Trading bot is the thing itself, including what you are buying when somebody sells you one.
And systematic trading is the method underneath both: a decision made once, in advance, rather than at the right-hand edge.
I have had a script sit there convinced it was flat while the broker had a position open underneath it, and the distance between those two beliefs is the worst feeling I know in this business. It was not a clever failure either - the connection dropped during a restart and the program came back with no memory of what it had already done. What fixed it was not better code. It was a switch I could hit from my phone that closed everything and stopped the thing, tested on a quiet afternoon when nothing was on.
— Michael Whitman
This page is educational, not financial advice. Test every idea on your own charts before risking money.