Backtesting a Trading Strategy

Backtesting a Trading Strategy

In this article you will learn how to start backtesting a trading strategy before you start using it in current market conditions.

Do you have great market ideas but don’t know how to put them to the test without putting your money at risk? A good systematic trader’s bread and butter is learning how to backtest trade ideas.

Backtesting is based on the premise that what worked in the past may work again in the future. But how do you go about accomplishing this on your own? And how should you assess the outcomes? Let’s go over a basic backtesting procedure.

Backtesting is an important part of creating your own charting and trading strategy. It is accomplished by using a system based on historical data to reconstruct trades that would have occurred in the past. Backtesting results should give you a general idea of whether or not an investment strategy is effective.

In a nutshell, backtesting is used to determine whether your trading ideas are viable. You use historical market data to determine how well a strategy would have performed. If the strategy appears to have promise, it may also be effective in a live trading environment.

What to do before you start backtesting

There is one thing you should know before we begin with the backtesting example. You must first determine what type of trader you are. Are you a swing or a systematic trader?

Discretionary trading is decision-based; traders use their own discretion to determine when to enter and exit positions. It’s a relatively loose and open-ended strategy in which most decisions are made based on the trader’s assessment of the current conditions. Backtesting is less relevant in discretionary trading, as expected, because the strategy is not strictly defined.

This is not to say that if you are a discretionary trader, you should never backtest or paper trade. It simply means that the outcomes may be less reliable than in the other case.

Systematic trading is more relevant to our discussion. Systematic traders rely on a trading system to define and tell them when to enter and exit positions. While they have complete control over the strategy, the strategy determines the entry and exit signals. Consider the following simple systematic strategy:

  • Enter a trade when A and B occur at the same time.

  • When X occurs, exit the trade.

Some traders prefer this method. It can help to eliminate emotional trading decisions and provide some assurance that a trading system is profitable. There are, of course, no guarantees.

This is why it’s critical to have very specific rules in place in your system for when to enter or exit positions. The results will be inconsistent if the strategy is not well-defined. As one might expect, algorithmic trading is more popular with this trading style.

If you want to do automatic backtesting, you can purchase backtesting software. You can enter your own data and the software will perform the necessary backtesting for you. In this example, however, we’ll use a manual backtesting strategy. It will require a little more effort, but it is completely free.

Backtesting a trading strategy

This link will take you to a Google Sheets spreadsheet template. This is a simple template that you can use to get started on your own. It gives you an idea of what information might be on a backtesting sheet. Some traders will prefer to use Excel or Python to code it – there are no hard and fast rules here. You can add a lot more data and anything else you think will be useful to it.

So, let’s run a simple trading strategy through its paces. Here’s our suggestion:

  • We purchase one Bitcoin at the first daily close following a golden cross. When the 50-day moving average crosses above the 200-day moving average, we consider it a golden cross.

  • At the first daily close following a death cross, we sell one Bitcoin. A death cross occurs when the 200-day moving average falls below the 50-day moving average.

As you can see, we also specified the time frame for which the strategy is applicable. This means that if a golden cross appears on the 4-hour chart, we will not consider it a trading signal.

For the purposes of this example, we’ll only look back until the beginning of 2019. However, if you want to get more accurate and reliable results, you can go much further back in Bitcoin’s price history.

Let’s take a look at the trading signals generated by this system over the course of the period:

  • Buy @ ~$5,400

  • Sell @ ~$9,200

  • Buy @ ~$9,600

  • Sell @ ~$6,700

  • Buy @ ~$9,000

Here’s how our signals appear on the chart:

Backtesting a Trading Strategy,backtesting trading strategy,backtesting trading strategy bitcoin,backtest trading strategy free,backtest trading strategy tradingview

Golden cross-death cross strategy. Source: TradingView.

Our first trade would have resulted in a profit of approximately $3800, whereas our second trade would have resulted in a loss of approximately $2900. This means that our current realized PnL is $900.

We’re also in an active trade with a $9000 unrealized profit as of December 2020. If we stick to our original plan, we’ll be able to close this when the next death cross occurs.

Backtesting Results Evaluation

So, what do these findings indicate? Our strategy would have produced a reasonable return, but it has yet to produce anything noteworthy. We could realize the currently open trade to drastically increase our realized PnL, but that would defeat the purpose of backtesting. If we do not stick to the plan, the results will be unreliable.

Despite the fact that this is a systematic strategy, it is also important to consider the context. The unprofitable trade from $9600 to $6700 occurred at the time of the COVID-19 crash in March 2020. A black swan event of this magnitude can have a massive impact on any trading system. Another reason to go back further is to see if this loss is an outlier or a byproduct of the strategy.

In any case, this is an example of a simple backtesting procedure. This strategy may hold promise if we test it with more data or include other technical indicators to potentially strengthen the signals it generates.

What else can backtesting results reveal?

  • Volatility measures: your maximum upside and drawdown.

  • Exposure: the amount of capital you need to allocate for the strategy from your entire portfolio.

  • Annualized return: the strategy’s percentage return over a year.

  • Win-loss ratio: how much of the trades in the system result in a win and how much in a loss.

  • Average fill price: the average price of your filled entries and exits in the strategy.

These are just a few examples and by no means an exhaustive list. It is entirely up to you which metrics you wish to track. In any case, the more details you record about the setups, the more opportunities to learn from the results you’ll have. Some traders are very strict with their backtesting, which may show up in their results.

The final point to consider is optimization. If you’ve read our backtesting article, you’ll understand the distinction between backtesting and forward testing, also known as paper trading. Testing and optimizing your ideas in a real-time trading environment can be beneficial.

We’ve covered the fundamentals of performing a manual backtest on a trading strategy. Remember that past performance is not a guarantee of future success.

Market environment change, and if you want to improve your trading, you must adapt to those changes. In general, it’s also a good idea not to blindly trust the data. When it comes to evaluating results, common sense can be a surprisingly useful tool.

Manage consent

error: Content is protected !!

Scroll to Top


About Author

Clarence Choe