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 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.

Table diagram of the three parts of a live trading system, signal, execution and monitoring, and which carry most of the work.
A diagram of the three parts this page describes: the signal is small, and execution and monitoring are most of the work.

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 pays the spread and any commission, whatever the bar did. On a quiet bar that fixed toll can swallow most of the move the rule was built to capture.

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.

How this connects

Pine Script is where many retail systems start. A strategy written on TradingView can raise alerts when its conditions are met, but the alert still has to reach a broker, and that hand-off is one more link that can fail silently.

A bracket order is the practical form of the resting stop. It sends the entry with a stop and a target attached at the broker, so both exits exist even if the program never speaks again.

Order type is a design decision, not a factory setting. A market order trades certainty of a fill for an unknown price, a limit order the reverse, and the program has to handle whichever failure its choice creates.

Grid trading is the design most dangerous left unattended, because it keeps adding positions against a trend that a person watching would have recognized.

Leverage shortens every reaction time. A bug that doubles a position on a leveraged account can reach a margin call before any monitoring alert is read.

And speed is not the retail edge. High frequency trading firms and market makers compete on dedicated hardware placed beside the exchange, so a home system that depends on being first is entering the one contest it cannot win.

When it fails

It keeps trading in a trading range when a person would stop. In a range the next bar often disagrees with the last, and a program that reacts to every turn pays to be whipsawed each time.

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. Say a round trip costs 0.02: that is 2% of a bar spanning 1.00 and 10% of one spanning 0.20 — 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

The title scan covered the 24,971 trading and investing videos in the finance search study this site keeps. “Automated trading” appears in 27 titles, median 10,749 views across 19 channels, maximum 149,372. “Trading bot” takes 93 videos at a 10,655 median; “algorithmic trading” or “algo trading” 191 at 6,204; “expert advisor” 7 at 11,637.

“Backtest” or “backtesting” appears in 462 titles from 354 channels, median 2,234 views. “Python trading” appears in three, median 2,546, and “risk of ruin” in none at all.

The question: The script crashed with a position on. Now what?

Roughly 318 videos cover the automation terms and 462 cover backtesting, against zero on risk of ruin and three 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 drawdowns a live system must sit through. The S&P 500 went through 68 separate slides of 5% or more below its record between 1950 and 2026, close to one a year, so the decision to switch a system off is not a rare event but an annual one. Every round trip also pays the spread and commission, 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.

The practical check

The worst failure in automated trading is a script convinced it is flat while the broker holds a position underneath it. It does not take a clever bug — a dropped connection during a restart can bring the program back with no memory of what it already did. Better code is not the fix; a switch you can hit from your phone that closes everything and stops the program, tested on a quiet afternoon, is.

— Michael Whitman

This page is educational, not financial advice. Test every idea on your own charts before risking money.