What Is Algo Trading? How It Works, the US Rules, and a Real Rule Run on SPY
Algorithmic trading, or algo trading, means a computer places trades by following a written rule. The rule says what to buy, when to buy it, how much, and when to sell. Writing the whole rule is the hard part, and the code is the easy part.
Algorithmic trading, or algo trading, is trading by a written rule precise enough for a computer to run with no further instruction: what to buy, when, how much and when to get out. The code is usually the easy part. The hard part is finishing the rule.
Banks use algorithms to slice large orders, market makers use them to quote all day, and a retail trader can use one to run a single moving average rule. This page covers how the pieces fit, one simple rule traded on real SPY prices with its losses, what SEC data shows about the orders algorithms send, and what US law requires.
How does algo trading work?
An algorithm has three layers, and each one answers a different question:
| Layer | The question it answers | Example |
|---|---|---|
| Signal | When to act | The close crosses above a moving average |
| Order | How to act: market or limit, how big, in how many pieces | Buy at the next open |
| Risk check | Whether the order is allowed to leave | Refuse anything over a preset dollar limit |
Signal algorithms are what most traders mean: trend following, mean reversion, arbitrage between two prices of the same thing, or a crossover like the one traded below. Execution algorithms do not choose the trade at all. A VWAP algorithm, for example, spreads a big order across the day so it trades near the day’s average price.
Speed is a separate question. A daily rule that places one order after the close is algorithmic trading. So is a high frequency firm sending and canceling quotes in microseconds. What makes it algorithmic is that the rule, not a person, makes each decision.
What does a complete algo trading rule look like?
Here is a common entry: buy when the close crosses above the 20-day simple average. A computer can run it, but it is only one of the five sentences a complete rule needs.
| Sentence | The rule traded on this page |
|---|---|
| 1. Market and chart | SPY, daily bars, regular session |
| 2. Entry | After a close above the 20-day average that follows a close at or below it, buy at the next open |
| 3. Exit | Sell at the next open after any close at or below the average; the same sentence covers the loss and the gain |
| 4. Size | $10,000 per trade, whole shares |
| 5. Costs | What the broker and regulators charge on each sale, and the gap between the price the rule saw and the price it got |
Try writing your own approach this way, and the sentence will usually stop somewhere, at “when the structure looks right” or “with enough confirmation”. Each place it stops is a decision you have been making differently each time. A decision that was never written down cannot be reviewed.
The exit and the size have their own pages. A price-level exit is a stop order, with its own gap risk, and the position size calculator turns a dollar risk and a stop into a share count.
Every number in a rule is a choice. On SPY since 1993 a 5-day average gave 1,121 signals and a 60-day average 275. Try every length, keep the one that looked best, and you have measured which setting fitted the past, which is overfitting.
An algo trading rule on real prices: SPY, September to October 2026
The five sentences above, run on every signal from 1 September to 30 October 2026. Prices are SPY’s real opens and closes from Yahoo Finance. Shares are $10,000 divided by the entry price, rounded down.
| Signal close (vs average) | Bought at the open | Close at or below the average | Sold at the open | Shares | Result before fees |
|---|---|---|---|---|---|
| 3 Sep: $773.17 vs $769.21 | 4 Sep: $772.01 | 8 Sep: $765.96 | 9 Sep: $764.08 | 12 | -$95.16 |
| 21 Sep: $773.50 vs $764.69 | 22 Sep: $774.03 | 29 Sep: $764.20 | 30 Sep: $766.45 | 12 | -$90.96 |
| 2 Oct: $769.64 vs $764.83 | 5 Oct: $769.69 | 14 Oct: $769.60 | 15 Oct: $766.25 | 12 | -$41.28 |
| 15 Oct: $771.79 vs $771.11 | 16 Oct: $773.24 | 16 Oct: $763.25 | 19 Oct: $767.23 | 12 | -$72.12 |
| 21 Oct: $773.09 vs $770.88 | 22 Oct: $766.37 | 22 Oct: $763.96 | 23 Oct: $759.90 | 13 | -$84.11 |
| 28 Oct: $772.31 vs $770.90 | 29 Oct: $768.79 | 29 Oct: $769.36 | 30 Oct: $761.38 | 13 | -$96.33 |
Check one row by hand. The 2 October trade bought 12 shares at $769.69 and sold them at $766.25: 12 x ($766.25 - $769.69) = -$41.28. The SEC’s fee of $20.60 per million dollars of sales, the rate in force since 4 April 2026 and still current as of 20 November 2026, adds 12 x $766.25 x 0.0000206 = $0.19. All six trades lost: $479.96 before fees, $481.12 after $1.16 of SEC fees. FINRA’s trading activity fee, charged per share sold, is left out. FINRA set it to $0.00 for trades from 1 October to 31 December 2026 (rule filing SR-FINRA-2026-021 and FINRA’s billing questions page, both read on 20 November 2026). Before that it was $0.000195 a share, which is under one cent on each of the two September sales.
What the table teaches is not the result. Six trades in a sideways two months say nothing about the rule over decades. Two rows show what writing it down exposed. On 2 October the trade was $9.40 a share ahead at the 6 October close of $779.09, and the exit gave all of it back, because the rule only sells after a close below the average. On 22 October SPY opened at $766.37, already under the signal day’s average of $770.88, and the rule bought anyway, because nobody wrote a sentence about a gap through the line. A computer follows the sentence it was given, including the gaps in it.
One more cost nobody wrote down: tax. Each of the first five losing sales was followed within 30 days by a new purchase of SPY. That is the pattern IRS Publication 550 defines as a wash sale, which blocks the loss for that sale and moves it into the next shares’ cost. A rule that trades one fund in and out does this all year.
How often did the algo rule’s entry turn straight back?
On Yahoo Finance’s SPY daily bars from 29 January 1993 to 26 October 2026, the close crossed above its 20-day average 515 times. Of the 514 with five sessions to follow, 124 (24.12%) were back at or below the average the very next session, 225 (43.77%) within 3 and 278 (54.09%) within 5. Of all 5,365 closes above the average, signal or not, 33.10% were back at or below it within 5 sessions. A fresh crossing sits right on the line, so it turns back far more often.
| Average length | Signals since 1993 | Signals a year | Back at or below the average within 5 sessions |
|---|---|---|---|
| 5-day | 1,121 | about 33 | 71.96% |
| 10-day | 754 | about 22 | 55.11% |
| 20-day | 515 | about 15 | 54.09% |
| 30-day | 411 | about 12 | 53.90% |
| 60-day | 275 | about 8 | 47.64% |
No length kept a clear majority of its signals above the line for a week. Nasdaq’s SPY history since October 2016 gives the same 124 signals on the same dates as Yahoo’s bars over those years. Every length is in the crossover file and every 20-day signal in the signal list. One fund, no costs, and a reversal here counts closes, not trade results.
What SEC data shows about algorithmic orders
The SEC’s MIDAS system records every order, cancel and trade message on the exchanges whose direct feeds it reads. The newest quarter posted as of 20 November 2026 is the second quarter of 2026, 1 April to 30 June, 62 sessions. A lit trade is a trade against a displayed order; the SEC’s ratio leaves out trades against hidden orders.
| Name | Cancel messages per lit trade | Share of order shares that traded |
|---|---|---|
| Median stock (3,723 stocks) | 16.30 | 3.81% |
| Median stock in the largest tenth by market value | 15.18 | 3.86% |
| Nvidia (NVDA) | 21.13 | 3.95% |
| Apple (AAPL) | 25.54 | 3.31% |
| SPY | 65.96 | 0.86% |
| QQQ | 133.28 | 0.44% |
SPY drew 1,350,281,175 cancel messages against 20,472,387 lit trades. Orders were placed for 145.95 billion SPY shares, and 1.25 billion traded on those exchanges.
People do not cancel a billion orders a quarter; programs that keep re-pricing quotes do. The data does not say who sent each message. So it shows the footprint of automated quoting, not a share of trading done by algorithms. Every ticker is in the MIDAS file.
For a retail rule this matters because the quote you see may be gone before your order arrives. The bid-ask spread page measures the gap those quotes leave, and the order book page shows how long they stay.
Is algo trading legal? The US rules
Yes. Running your own rule through a broker is legal. The rules fall on the firms that touch the market, and four are worth knowing. Each was read on the regulator’s own site on 20 November 2026:
| Rule | Date | What it requires |
|---|---|---|
| SEC Rule 15c3-5, the market access rule | adopted 3 November 2010 | A broker with market access must block orders over preset credit or capital limits, and orders that look erroneous, before they reach the market |
| FINRA Regulatory Notice 15-09 | 26 March 2015 | Guidance for member firms on supervising and controlling algorithmic strategies under FINRA Rule 3110 |
| FINRA Rule 1220(b)(4) | current text, read 20 November 2026 | At a member firm, the person mainly responsible for designing, developing or significantly changing an algorithmic strategy in stocks, preferred shares or convertible bonds registers as a Securities Trader |
| CFTC Electronic Trading Risk Principles | effective 11 January 2021 | Futures exchanges must have rules and pre-trade risk controls for all electronic orders, in full by 12 July 2021 |
The market access rule ended “naked” access, so your bot’s orders pass your broker’s checks. The CFTC principles replaced Regulation AT, a stricter proposal the CFTC withdrew on 25 June 2020.
None of the four asks a retail trader to register anything to run a rule in their own account. The broker’s checks apply to the orders instead.
What a backtest of an algo trading rule will not tell you
Run a complete rule over history in a backtest and three faults make it look better than live trading would.
| Fault | What it is | How the worked rule handles it |
|---|---|---|
| Look-ahead | Acting on a close at that close, before the bar has ended | It buys at the next open |
| Survivorship | Testing on today’s index members, which skips the companies that were removed | It trades one fund, not a list of stocks |
| Costs | A test with no spread or fees trades a market nobody trades in | It counts the SEC fee and names what it leaves out |
The scalping page shows why a rule that trades often feels costs the most.
Where algo trading goes wrong
| What goes wrong | The evidence on this page |
|---|---|
| About half the signals reverse within a week | 278 of 514 SPY signals from the 20-day average were back across it within 5 sessions |
| The rule does what it says | The 22 October gap and the 2 October giveback were both the rule working as written |
| The rule was tuned on its own test | The 5-day average and the 60-day average gave very different signal counts on the same prices |
A precise rule is not a right rule. The rule cannot tell in advance which signals will reverse. Automation removes hesitation, not losing trades.
Read your sentences for the cases they skip, then decide those cases on paper.
Choosing the best setting on a period and then judging it on that same period measures nothing. It is the most common error in this whole subject.
Questions people ask
Is algo trading really profitable?
Some firms profit from it, but no rule is profitable just because a computer runs it. The six-trade example above lost money, and over 33 years more than half of its signals turned back within a week. Costs and exits decide what an entry is worth.
Is algo trading legal in the USA?
Yes. Your broker must run pre-trade risk checks on your orders under SEC Rule 15c3-5, and FINRA’s registration rule covers people who build algorithms at member firms, not your own account.
Do I need to code to do algorithmic trading?
Not to start. The hard part is writing the five sentences; many charting platforms can run them, and the automate a strategy page covers the steps.
How many signals does a moving average rule give?
It depends on the length. On SPY’s daily chart from 1993 to 2026 the 5-day average gave 1,121 signals, the 20-day 515 and the 60-day 275: about 33, 15 and 8 a year.
Related
Entry and exit is the half of a rule most people leave unspecified, as the 2 October trade showed.
Risk management turns a signal into a position size you can survive.
And moving average is the tool the example rule is built on, including why its length is a choice rather than a setting.
Even if you never run a bot, try writing your strategy as a rule, because the exercise is brutal in a useful way. You may find you cannot finish the sentence: you know what a good setup looks like and cannot say it in a way a computer would accept. That gap between what you think you do and what you can spell out is worth more than any indicator.
This page is educational, not financial advice. Test every idea on your own charts before risking money.