Skip to content
Bajamar

Guide

How to backtest a trading strategy without fooling yourself

To backtest a trading strategy honestly, write the rule down before you look at the data, count every cost, and compare the result with two plain alternatives: the same strategy entering at random, and simply doing nothing. If it cannot beat both after costs, over enough trades, it has no edge you can rely on. And even if it can, the past is not the future: a backtest is a filter for bad ideas, not proof that a good one will keep working.

What a backtest is, and what it is not

A backtest replays a rule over past prices and records every trade it would have made: when it would have bought, when it would have sold and what would have been left after costs. It answers one narrow question: would this exact rule have worked in that exact past?

It is not a forecast. Markets change, and a rule that fit one stretch of history can fail in the next. Think of a backtest as a cheap way to throw out bad ideas, not as a way to prove good ones.

Two benchmarks every strategy must beat

Doing nothing. Compare the strategy with simply holding the asset over the same dates. In a rising market almost any rule that buys looks clever; the question is whether it did better than not trading at all.

Random entries. Keep everything about the strategy the same, the exits, the size and the number of trades, but pick the entry times at random. Run hundreds of these random versions. If your rule does not beat the large majority of them, say 95 out of 100, its entry signal adds nothing you could not get by luck.

Count every cost

A backtest without costs is fiction. On every trade, count the network fee, any priority fee, the fees of the markets the swap goes through, slippage and the impact of your own order on the price, on the way in and on the way out.

Be pessimistic about fills. Assume you buy a little higher and sell a little lower than the price in your data, especially in thin markets or right after a sharp move, when everybody is trying to trade at once.

Then stress it: double the costs and run it again. A strategy whose edge disappears as soon as costs rise a little never had much of an edge.

Overfitting: when a strategy learns the past by heart

Every parameter you add and every tweak you make after looking at the results helps the rule fit the noise in your data. With enough knobs, any history can be made to look profitable, and none of that carries over to what comes next.

Write the rule before you test it, and do not change it after seeing the results. If you try variants, count all of them, including the ones that failed. Testing twenty versions and showing the best one is not a test; it is a lottery with the winner picked afterwards.

Keep part of the data aside. Build and adjust the rule on one period, then run it once, untouched, on a period it has never seen. If the result collapses there, the first one was luck.

Too few trades, too little history

A dozen trades is noise. With few trades, a single lucky winner can make a whole strategy look good. Look for dozens of trades at the very least, spread over different days and different market conditions.

Do not judge by the total alone. Look at the average result per trade after costs, together with its margin of error, the worst drop along the way and the longest losing streak. A strategy you could not stomach through a bad month is a strategy you will abandon at the worst moment.

Other ways a backtest can lie

Using data that did not exist yet. Relying on information that was not available at the moment of the decision, such as a day's closing price to decide a trade during that same day, makes any rule look better than it could ever be.

Keeping only the survivors. In crypto a great many tokens disappear; testing only on the ones still around today hides every token that went to zero.

Imaginary liquidity. Assuming you could buy or sell any amount at the price in your data ignores that your own order moves the market, and that some tokens have almost no buyers right when you need them.

The past is not the future

Even a clean pass is not a promise. The next step is to run the same rule forward, in simulation on live prices, without changing it, and see whether it holds up. If you then move to real money, expect it to come out worse, and remember that trading crypto can cost you all the capital you put in.

How Bajamar tests its own strategies

Bajamar, a free trading bot for Solana, writes every rule before the data is seen and does not touch it along the way. Each strategy is compared with holding SOL over the same dates and with itself entering at random, in 300 versions.

A strategy only has a proven edge with at least 30 trades closed by the strategy itself over 10 days or more, if it is better than 95 out of 100 random versions, beats holding SOL and stays above zero on average after costs, with its day-by-day margin of error and everything tried in its family counted. To move to real money, it also has to beat plain lending. Its closed tests use prices from 2024 to 2026, costs included. So far, 16 strategy rules have been put through formal tests, and none has cleared its bar.

Frequently asked questions

What is a good backtest result?

Not a big number. A good result comes from a rule written before the test, beats random entries and doing nothing after costs, holds up over enough trades and survives on data it was not built on. Even then it is a reason to keep testing, not a promise.

How many trades does a backtest need?

There is no magic number, but a handful is never enough: dozens at the very least, over different periods. Bajamar, for example, does not treat an edge as proven with fewer than 30 trades over 10 days or more.

What is overfitting in trading?

Tuning a strategy so closely to past data that it learns the noise instead of anything real. It shows up as a strategy that looks excellent on the data it was built on and falls apart on new data.

Why compare a strategy with random entries?

Because many results come from the direction of the market, not from the signal. If random entries with the same exits do just as well, the signal adds nothing.

Does a good backtest mean the strategy will make money?

No. A backtest shows what would have happened in one particular past. Markets change, real costs and liquidity are usually worse, and past results, measured or simulated, do not predict future ones.

A single app, no Node, no terminal

The desktop app for Mac and Windows carries the bot inside: double-click, wallet, and try it in simulation. Helping the network is up to you.

Download the app

More guides