Tickfloor

How to backtest a trading indicator properly

Write the rule down exactly, test it on past prices with costs, check it on data it has never seen, compare it with random entries, and count how many versions you tried. If it still looks good after all five, it deserves a closer look. If not, you found out cheaply.

Last updated

Why bother? In our own tests, 1,342 strategies built on common indicators produced 0 that passed once we corrected for luck across 1,774 tests. This is a backtest, in-sample, not a promise. The steps below are the ones that sorted the lucky from the rest. For the full picture, see do trading indicators actually work.

1. Write the rule down exactly

"Buy when RSI is low" is not a rule. "Buy at the close when the 14-day RSI falls below 30, sell when it rises above 50" is. Decide the entry, the exit, the stop and the position size before you look at any results. If you change the rule after seeing the results, you are fitting it to the past.

2. Add costs

Every trade costs money: fees, the gap between buy and sell price (the spread), and slippage, which is getting a worse price than you saw. Small costs add up fast on rules that trade often. In our quick tests, the same rule lost far less at a low fee than at a high one, and the rules that won most of their trades still lost money after costs. If your backtest has no costs, treat the result as a ceiling, not an estimate. This is a backtest, in-sample, not a promise.

3. Test on data it has not seen

Split your history in two. Build and tweak the rule on the first part (in-sample). Then test it once on the second part (out-of-sample). The second part is your honest result. If you keep going back and tweaking, it stops being unseen.

4. Compare with random entries

Keep your exits and position sizing, but enter at random times. Do it a few hundred times. If your indicator cannot beat the random versions, then the indicator is not doing the work. The exits, or just the market going up, might be. This is called a random-entry control.

5. Correct for how many things you tried

If you tried 20 settings and kept the best, that best one looks better than it is. Count every version you tried, and ask how good the best of that many luck-only tries would look. This is the multiple-testing correction. Our free luck checker does a simple version of it from your trade list.

Where the TradingView strategy tester fits

The Strategy Tester in TradingView is the most common free way to backtest an indicator. It is good for a quick first look. You can see a trade list, an equity curve and basic stats on the chart you are already studying. That is useful for checking you coded the rule you meant to.

It does less than the five steps above. Commission and slippage start at zero until you set them. It has no built-in split between in-sample and out-of-sample data, no random-entry comparison and no count of how many versions you tried. You can still do those steps by hand or with other tools. Treat its numbers as a starting point.

A quick checklist

Passing the checklist is not a promise it will work next month. It just means luck is a less likely explanation. In-sample, not a promise.

Questions

How many trades do I need for a backtest to mean anything?

More is better, and there is no magic number. A rule that fires 20 times has told you very little. Hundreds of trades across more than one market is a sturdier base. Fewer trades means more room for luck.

What is out-of-sample testing?

You build the rule on one slice of past prices, then test it once on a later slice you never looked at. If it only works on the slice you built it on, it was probably fitted to noise.

Is the TradingView strategy tester good enough?

It is a fine first look at how a rule would have traded on a chart. Set commission and slippage yourself, because they start at zero. It does not split your data, compare with random entries or count your tries, so do those separately.

General information only. It doesn't consider your objectives, finances or needs. Tickfloor holds no financial services licence and never places trades.