Free code Tom Basso's trend rules
My AI Tests Famous Trading Systems
Tom Basso's trend rules and position sizing, free Python backtest
My AI coding agent read 9 long interviews with Market Wizard Tom Basso, rebuilt his trend rules and his position sizing, and tested four of his claims on 24 ETFs. It checked its own work. This is the code it wrote: the full Python backtest.
Download the code (zip, 17 KB) Source on GitHub
Free, with no sign-up. This is an experiment in what AI agents can build and verify, not trading advice.
The honest result
Before costs, coin-flip entries beat Basso's entry rule: a median of +3.1% a year against +2.6%. After costs, only 14% of the coin-flip runs made money, and his system beat 89% of them. But his system made only +0.4% a year after costs. SPY, bought and held, made +10.7% a year. The profit before costs came from his exits and his sizing, not from his entry.
+3.1%
a year before costs. Median of 100 coin-flip runs with his sizing. His entry rule made +2.6%.
14%
of 500 coin-flip runs made money after costs. His system beat 89% of them.
+0.4%
a year after costs. His 21-day system with his full sizing. SPY, bought and held, made +10.7%.
30 of 2,992
trades made $11.6M on a $10M account. The other 2,962 trades lost $14.1M.
| Test | Before costs | After costs |
|---|---|---|
| Coin flip, median return a year | +3.1% | −1.8% |
| Coin-flip runs that made money | 94% of 100 | 14% of 500 |
| His 21-day Keltner system, return a year | +2.6% | +0.4% |
| SPY, buy and hold, return a year | +10.7% | +10.7% |
- The test used 24 ETFs, daily prices from March 2007 to November 2026, and a $10,000,000 account. Costs are 0.05% of the traded value on each side. Cash earns the Treasury bill rate, as in a futures account. Buy and hold pays no trading costs.
- His system enters with a stop order at the 21-day exponential average plus or minus 2 times the 21-day average true range (a Keltner channel). It exits and reverses at the opposite band. The coin flip uses his sizing, a random long or short entry, and a trailing stop 3 times the average true range away. So the exits are not the same.
- Random entries trade about 1.8 times as often as his system: 5,258 trades against 2,992. That is why costs reverse the result.
- His four sizing layers, added one at a time to the same 2,992 trades, cut the worst drop from 44% to 39%. They did not turn a flat system into a profitable one. SPY's worst drop was 55%.
- His system won 34.7% of its trades. Basso says he wins about a third.
- With a 50-day lookback in place of 21, the system made +4.0% a year after costs. Slower settings paid more on this data. Picking 50 now would be the optimization that Basso warns against.
- ETFs stand in for the futures that Basso traded. The test uses one of his three band indicators, and none of his other strategies. 2007 to 2026 was a hard period for trend following.
- Past results do not predict future results.
TradingView
This episode has no TradingView script. The agent built the test in Python only. Basso's sizing caps the total risk of all open positions together, across the whole portfolio. A TradingView strategy tests one symbol, so it cannot show the part of the system that did the work.
What is in the zip
README.md- What the test found, the rules in short, and why there is no TradingView script.
RESULTS.md- The setup, the four tests, the result tables and the limits. It links to the time in each of Basso's talks where he gives a setting.
python/- The full backtest: the engine, the data download, the four tests and the charts from the video.
Run the Python backtest
From the python/ folder, with Python 3.12 or later:
pip install -r requirements.txt
mkdir -p data results
python fetch.py data
python sizing_study.py data results
python more_tests.py data results 500
python cost_check.py data results
python charts.py results
How the agent checked its work
- Before it trusted the first run, the agent checked the accounting. The profit of every closed trade plus the open positions matched the change in the account exactly.
- The agent caught a mistake in its first chart. The subtitle said that the coin-flip runs used the same stops as his system. They do not: they use a 3 times average true range trailing stop. It fixed the chart before it shared it.
- The scripts in the zip, run again on the saved prices, write the same result files, byte for byte.
The rules and the sizing settings come from Tom Basso's own talks and interviews, 2016 to 2026. RESULTS.md links to the time in each video where he gives them.
The video
Coin Flips Beat Tom Basso's Entry Until Costs Hit
Download the code All free code
This is an experiment in what AI agents can build and verify, not trading advice. The code is free to use, change and share.