Guide
How to backtest a trading strategy for free
A backtest replays a strategy over past days to show what it would have done. On Retro the backtest runs the same Python file that later trades, minute by minute, so the thing you test is the thing that runs. Stock, ETF and coin backtests are free for up to two months of history each.
What a backtest can and can't tell you
A backtest shows how a rule behaves: how often it trades, how large its wins and losses are, and how deep its worst stretch goes. It is the cheapest way to throw out an idea that never worked.
It can't tell you what happens next. Fills are estimates, and a rule that did well on past days can lose money on new ones. Treat a good backtest as a reason to keep testing.
How a backtest works on Retro
- The same code. The backtest runs a frozen copy of your program as it is saved, once for every minute of its timetable, over the days you name.
- Finished bars only. Prices come from your broker's one-minute history, cut off at the simulated time, so your program never sees a bar that hadn't finished yet.
- Fills. A market order fills at the minute's open, one hundredth of a percent worse unless you set your own slippage. A limit order fills in the first bar that reaches its price. A stop fills where a bar reaches it, a little worse, and when one bar reaches both sides of a bracket, the stop is the one that fills.
- An account of its own. A backtest trades a simulated account, so nothing touches your brokerage account.
- Speed. A day of one-minute passes takes about a minute and a week a few minutes. You can close the page while it runs.
Step by step
Write the rule down
Every strategy on Retro is a program. Write it in Programs, or describe it to Claude and let Claude write it (how to build a trading bot with AI). Be exact: "buy when SPY closes above its 20-day high" can be tested, and "buy when it looks strong" can't.
Run it once
A test run starts the program against live prices with every order refused. It shows that the code starts, reads the market and decides what you meant.
Pick the days and start the backtest
Choose a span of days and a timetable. Include calm days and rough ones, since a rule that has only seen a rising market hasn't really been tested.
Read the result
Look past the final number. Count the trades, find the largest loss and the longest losing streak, and check whether one day made most of the profit. Read what the program printed on a few trades to be sure it did what you meant.
Change one thing and test again
Backtest the same days after each change so the comparison is fair. Keep some days aside and test on them only at the end.
Mistakes that make a backtest look better than it is
- Looking ahead. Using a price the rule couldn't have known yet, like the day's close at noon. Retro's history stops at the simulated time, but anything your program reads from outside your broker isn't turned back in time.
- Overfitting. Tuning the numbers until the past looks perfect. The more settings a rule has, the easier it is to fit noise.
- Leaving out costs. Slippage and spreads add up for a rule that trades often. Set a realistic slippage; options fill at the real bid and ask.
- Too few trades. Ten trades can't tell skill from luck. Test long enough to see many.
- What no backtest counts. Splits, dividends and how much size the market could have taken aren't in the result.
Faster backtests
Retro's own Python library is the fastest way to backtest, and a program can skip the minutes it does nothing in, so a rule that acts once a day runs once a day. See Fast backtests in the docs.
What's free, and what comes with Retro Data
| Free | Retro Data | |
|---|---|---|
| History per backtest | Up to two months | Up to two years |
| Passes per backtest | Up to 20,000 | Up to 200,000 |
| Stocks, ETFs and coins | Yes | Yes |
| Options at real minute quotes | — | Yes |
Retro Data is a monthly subscription on the data page. Test runs and traders need nothing.
More guides
- Build a trading bot with AI: Describe your rules in plain words, and Claude writes, tests and runs them as a Python program.
- Backtest 0DTE options on real quotes: Same-day SPY, QQQ, SPX and XSP options on the real bid and ask of every minute, and what to get right.