In order to find the best way to backtest a stock trading strategy, you need to first know what a backtester is and does. The Backtesting strategy is a simple concept.

Step 1: Identify the situation and retrieve similar cases from history

Take an economic event or a sudden shift in price or volatility and compare it to a number of similar situations in the past.

Step 2: Creating/running a strategy

Run your trade strategy through all these situations in the past while manipulating several variables. These variables include when to enter the market, the first and second profit targets, stop loss and risk/reward ratio etc.

Step 3: Optimization

  • Optimization refers to letting the computer calculate the best combination of the above-mentioned variables into a function.
  • Optimizing your backtests can be lead to overconfidence because the best combination of inputs for past situations doesn’t necessarily mean that it will profit in real trading.

Side note – Overfitting: A problem that can occur with AI is overfitting. Overfitting represents a model that correlates too closely with a particular set of data and it contains more parameters than can be justified by the data itself. Machine learning or AI tends to try to maximize its results on a set of data and ignores the suitability for future data.

  • It’s important to be mindful of the possibility of overfitting when you are running a backtest.
    • Gather more data, if you fit a model to twenty past situations, it is much more likely to predict the situation in the future.
    • Use Ensemble methods: you can use ensembling methods to consult and average several different models as it’s much more likely to produce optimal results for real trading.
    • Keep the model simple: If you try to fulfill too many parameters, the model will have too much capacity and overfitting can be a real problem.

Step 4: How to actually backtest

  • Now that you understand the concept of backtesting and optimization, I will demonstrate a few ways of backtesting.

Tradestation: These only work with price-driven trade ideas (if five consecutive green candles, then it will trigger a backtest). You basically pattern your system to recognize certain shifts in price or volatility and it will create a model that tries to adapt to similar situations in the future.

Building your own backtester: You can start from scratch and build your own backtester by various coding languages like Python or C++. It is not easy to build your own backtester because of various biases and how difficult it is to build an adequate model. Here is a website that explains more on how to build back testers.

Bettertrader: This is a tool that is built for backtesting news events and price-driven movements like for example oil moving up 3%. The advantage of using bettertrader is that a pre-existing model is built already for you and it only suggests statistically accurate trade-ideas to avoid bias.

In conclusion, backtesting is crucial for traders to gauge their strategy against historical situations before they engage in real trading with their strategy. One should be aware of when a model overfits its dataset by concentrating too heavily on a simple dataset. It’s necessary to be aware of how a model based on historical data might not predict a similar situation in real trading. While utilizing this tool, one should also combine several models to best represent the function that possibly represents future events in the market.

We hope you find the articles on the site helpful. A good place to start reading, if you haven’t already is:



Written by: Eyal Mor

We believe that traders need an edge that can only be gained by statistical analysis.

The way we accomplish that is by running statistical models in real-time and helping you to make the right decisions in real-time.

The Essential Guide to Trading Economic Events

Subscribe to our newsletter!

If you would like to:

  • Understand recent or current economic or news events
  • Know how the market reacted in similar situations
  • Get control over your trading

This product might be for you.


GET THE BETTERTRADER.CO APP!


  • BetterTrader App available on Apple store
  • BetterTrader App available on Google play store
  • BetterTrader App available on Web App
  • BetterTrader App available on TradingApp store

Most viewed posts

Recent Posts