Almost every trader has that moment where they think they've found the Holy Grail. They've tested an idea on historical charts, the results are absolutely stunning and they're convinced they've got it. Then they go and trade it with their own money and it completely collapses within a month. It's such a common occurrence that it's almost a rite of passage. The good thing is that backtesting is still one of the most useful things you can do, provided you understand how it can trick you.
A backtest is just applying your trading rules to past data to see how they would have performed. If your rule is to buy a pullback to the 21 EMA in a stock that's above its 50 day average, with a stop below the recent swing low, you can go right back through hundreds of charts and apply that rule mechanically to every single one of them and record the results. The whole point is to replace “I think that works” with actual numbers (your win rate, your average winner, your average loser, how bad your worst losing streak got etc).
Before you start you need your rules to be specific enough that someone else could follow them and get the same trades. “Buy strong stocks on a pullback” is not something that can be tested. “Buy when price closes within 1% of the 21 EMA, RSI is above 40, the stock is above its 50 day average and you have a stop below the lowest low of the last 5 days” is something that can be tested. Vague rules result in backtests where you just end up quietly selecting the trades that look good i.e. cherry picking.
The biggest trap is overfitting (also known as curve fitting). You keep fiddling with the parameters until the past results are perfect. The 21 EMA might have worked okay so you go to 19, then 23, then add a volume filter, then an RSI filter, then exclude Mondays. Eventually you've got a set of rules that would have made a fortune, but all you've really done is created a set of rules that describe the past noise. The real market won't reproduce that noise exactly. A red flag is a strategy with a lot of conditions and very specific numbers. A good strategy is one with a simple idea that works quite well over a wide range of settings rather than one that only works with a single magic number.
The fix is to test on data you haven't used to build the rules. That's out of sample testing. A fairly common approach is to build your rules on one period (say the first 70% of your data) and then run them once on the remaining 30% without making any changes. If they work then that's a good sign. If they collapse then the strategy was almost certainly fitted to the first period. Walk forward testing takes this a stage further by doing the above exercise over a number of rolling windows.
Sample size is important. 12 trades in your backtest will tell you absolutely nothing as a few lucky trades can completely swing the results. You generally need at least 30 trades to get anything meaningful and the more the better as small samples can be absolutely rubbish or absolutely great purely by chance. You also need to test across different market conditions. A strategy that has only ever been backtested in a bull market has not in any way been tested in a bear market or in a range-bound market.
Then there are the data problems. Look ahead bias occurs when your test inadvertently uses information that wasn't available at the time of the trade, for instance using the close of a candle to make a decision that you would have had to make prior to the close. Survivorship bias is when your data only contains the stocks that are still around today, i.e. you've excluded all the stocks that have gone bust or been delisted. That obviously makes everything look better than it is. Both of these are very easy to fall into and both will bias your results in a positive direction.
Real trading costs will also impact the results. Commissions are very low these days but slippage (the difference between the price you expected and the price you actually got) is still very much an issue, particularly in the less liquid stocks or on fast moving breakouts. A strategy with a tiny edge per trade can easily go negative when you take realistic slippage into account. It's a good idea to just assume your fills will be a bit worse than the backtest would have suggested and see if the strategy still works.
Look beyond total profit. Look at the maximum drawdown (the biggest peak to trough in your equity curve). A strategy that makes money but has a 40% drawdown is one that the vast majority of people simply can't stomach. Also look at the expectancy per trade and the longest losing streak as you're going to have to live with those losing streaks emotionally as much as you're going to have to live with the profits.
If you want to backtest without writing a single line of code you can do it by hand. Just go back through the charts of the stocks you're following, mark up every setup that fits your exact rules and then record the entry, stop and result in a spreadsheet. It's very slow but it's very educational and it forces you to be brutally honest about every trade, including the ones that go wrong. If you do code then of course you can use TradingView’s Pine Script strategy tester or Python (both of which are very popular) but the same warnings apply to both as a computer will happily test a bad idea 1000 times over.
Finally treat a good backtest as a reason to go and try the strategy rather than as proof that it works. The next stage is paper trading or very small real positions so you can see how it behaves in the real world. The market changes and an edge that existed in the past may well have disappeared. The point of backtesting is not to forecast the future. It's to eliminate the ideas that clearly don't work and to give you a realistic sense of what the potential returns on the ones that might be worth pursuing could be.

