From rules to an algorithm, and backtesting honestly
How to write a strategy precisely enough to test, how to read a backtest, and the mistakes that make backtests lie.
An algorithm, in trading, is just a set of rules precise enough that a computer could follow them without asking you a question. Writing those rules down is valuable even if you never automate them, because it exposes every decision you would otherwise make on feel.
What a complete strategy specifies
- Market and timeframe: for example, BTC-USD on daily candles.
- Entry: the exact condition, checked on a closed candle.
- Exit: the condition that closes a winning or losing trade.
- Stop: where you exit if the trade goes against you.
- Size: how much to trade, usually by risk per trade from lesson 5.
- Costs: the fees and slippage you will assume.
If a rule includes a word like 'strong', 'clearly' or 'looks like', it is not finished. Replace it with a number.
Reading the Algos demo backtest
The demo runs one deliberately simple rule: long only, buy when EMA 20 crosses above EMA 50 on a daily close, sell when it crosses back below, with a fee of 0.1 percent per side and no slippage. It fills each trade at the same daily close that produced the signal, a simplification you will meet again below. It shows the result next to simply buying and holding over the same period, along with three figures worth understanding.
Trade count tells you how much evidence there is. A handful of trades is an anecdote, not a statistic. Win rate is the share of trades that made money; for trend-following rules it is often below half, with profits coming from a few large winners. Max drawdown is the largest fall from a peak in the strategy's value to a later low. It is the number that tells you how painful the strategy would have been to live with, and for many people it matters more than the total return.
The demo uses a limited window of recent daily candles, so treat its numbers as practice in reading a backtest, not as evidence about the rule. Switch between symbols and you will often see the same rule look clever on one coin and poor on another over the same months. That variation is the lesson: a single backtest result says as much about the period tested as about the rule.
Why backtests lie
Backtests are hypothetical. They are run with hindsight, they involve no real orders, and they can be made to look good in many quiet ways. These are the most common:
- Overfitting: testing many settings and keeping the best one. With enough tries, something always fits the past by chance and then fails on new data.
- Ignoring costs: fees, spreads, slippage and, for perpetuals, funding. A rule that trades often can be profitable before costs and losing after them.
- Look-ahead bias: using information that was not available at the time, or using revised data. A mild form is filling at the very close that created the signal, as the demo does. In round-the-clock crypto the next candle opens at almost the same price, so the effect is small, but a real fill will differ.
- Survivorship bias: testing only on assets that still exist today and ignoring the ones that collapsed.
- Too little data: a rule tested only during one long bull market has never seen a bear market.
Testing honestly
The most important habit is out-of-sample testing. Split your history in two. Develop and adjust the rule on the first part only. Then run it, once and unchanged, on the second part. If the results fall apart on data the rule was not tuned on, you have learned something valuable cheaply. Walk-forward testing repeats this across several rolling windows. Also try nearby settings: if EMA 20/50 works but 18/45 and 22/55 do not, the result is probably luck.
Finally, compare with buy-and-hold on risk, not just return. A rule that earns less but with a much smaller drawdown may suit you better. A rule that earns more only by taking a deeper drawdown may be one you would abandon at the worst moment. The Algos paid plans, currently in early access, add a no-code strategy builder and backtests on more symbols so you can run these checks on your own rules.
Key takeaways
- A strategy is not finished until every rule is a number.
- Trade count, win rate and max drawdown matter as much as total return.
- Overfitting, ignored costs and look-ahead bias are the most common ways backtests lie.
- Always test on data the rule was not tuned on.
- Compare with buy-and-hold on drawdown as well as return.
Run the Algos demo backtest on BTC, ETH and SOL. For each, record the trade count, win rate and max drawdown next to buy-and-hold, then write one sentence on whether you would have stuck with the rule through its worst drawdown.
Run the crossover backtest