WhitmanTrading

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 candlestick chart of the site's shared price history. The headline on the chart reads: The rules run without you pressing anything.
The rules run without you pressing anything. Illustrative chart - not real market data.

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 gently rising stretch of the long price series with an account equity curve beneath it. The headline on the chart reads: Signal, execution, monitoring - and only one is fun.
Signal, execution, monitoring - and only one is fun. Illustrative chart - not real market data.

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

A calmly advancing stretch of the long price series with a slowly rising equity curve beneath it. The headline on the chart reads: Execution is where most home-built systems actually fail.
Execution is where most home-built systems actually fail. Illustrative chart - not real market data.

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 flat, quiet stretch of the long price series with a gradually rising equity curve beneath it. The headline on the chart reads: A dropped connection with a position open is the real risk.
A dropped connection with a position open is the real risk. Illustrative chart - not real market data.

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.

A strongly rising stretch of the long price series with an account curve breaching its limit. The headline on the chart reads: So a kill switch is the first thing to build.
So a kill switch is the first thing to build. Illustrative chart - not real market data.

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.

A choppy, directionless stretch of the long price series. The headline on the chart reads: And without logs you cannot tell what it did.
And without logs you cannot tell what it did. Illustrative chart - not real market data.

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.

A declining stretch of the long price series. The headline on the chart reads: Live results drift from the test, and you must measure that.
Live results drift from the test, and you must measure that. Illustrative chart - not real market data.

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

A 72-bar candlestick section of the shared price history with an account curve shown with and without fees. The headline on the chart reads: Automation multiplies trade count and therefore cost.
Automation multiplies trade count and therefore cost. Illustrative chart - not real market data.

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 candlestick chart with a volume histogram beneath it, with the volume histogram emphasised. The headline on the chart reads: A thin market is where slippage stops being small.
A thin market is where slippage stops being small. Illustrative chart - not real market data.

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 long-horizon candlestick view of the same price series. The headline on the chart reads: A slower system is far easier to automate safely.
A slower system is far easier to automate safely. Illustrative chart - not real market data.

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.

A candlestick series containing several opening gaps, with the largest opening gap marked. The headline on the chart reads: And the gap is the event the code never saw in testing.
And the gap is the event the code never saw in testing. Illustrative chart - not real market data.

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 declining stretch of the long price series, with the entry price and the level at which a stop would trigger drawn as horizontal lines. The headline on the chart reads: The stop has to live at the broker, not in your script.
The stop has to live at the broker, not in your script. Illustrative chart - not real market data.

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.

A candlestick chart of the site's shared price history, annotated with the round-trip cost. The headline on the chart reads: Every round trip costs 2% of a bar.
Every round trip costs 2% of a bar. Illustrative chart - not real market data.

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

A sideways, range-bound candlestick series. The headline on the chart reads: In a range it keeps trading when a person would stop.
In a range it keeps trading when a person would stop. Illustrative chart - not real market data.

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.

A strongly rising stretch of the long price series, cut short at the decision bar. The headline on the chart reads: The script crashed with a position on. Now what?
The script crashed with a position on. Now what? Illustrative chart - not real market data.

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.

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.

What I actually do

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.