Backtesting a Trading Strategy

How to Backtest a Trading Strategy + Free TradingView Strategy 2021

How to Backtest a Trading Strategy

Backtesting is something you should always do with your strategy before using real money to turn a profit. Backtesting relies on the idea of something working in the past working in the future. You do this to determine if your system is profitable ahead of time to prevent losses if the strategy is not working. The easiest method to backtest a strategy you go back in time and follow all the signals available to you, then determine if your investments would’ve yielded you a profit or a loss.

Backtesting

Backtesting shows you if the strategy you came up with will work. Sometimes strategies we come up with show all the right signals, but if you were to put the strategy into practice, it could yield you a loss. But how would you have known that? Backtesting is the answer. You would not have even applied the strategy if you knew it’s not great, or instead found an even better strategy and replaced your old one.

Type of Exit

There are two methods of exiting a trade which you must decide on. An exit strategy will influence how your strategy is developed. If you’re relatively new to trading or have never had a clear exit strategy, it’s best if you give systematic exits a shot. Systematic exits are when you have a clear set of conditions that need to be met to exit a trade, so it removes all emotion and stress. More advanced traders will be able to reflect on the state of the market and exit when they consider it the right moment. For less experienced traders, this is not recommended. 

Systematic trading is drastically easier to backtest because you will have a clear exit every time you enter a trade. Meanwhile, if you do not have a systematic exit, you might be biased in testing your strategy and might take more significant risks during testing, which will skew your results. Let’s get to backtesting.

How to Backtest

When backtesting, you have got to remove all emotion out of the test. Understand that omitting data if it does not make your strategy look good will harm you when you use the system with real money. Now, let’s get started.

First, you will need a way to store your backtest results to draw conclusions from data afterward. There are various ways to do this. Your best friend here will be a spreadsheet program. Easiest would be to use something like Google Drive Sheets or alternatives like LibreOffice, etc. Or you could even use a simple text editor, whatever works for you.

From our experience, Tradingview is a great free tool where you have lots of play in what you can do with it. Otherwise, you can use an alternative to TradingView – what you feel comfortable with using. We will be using Tradingview for our example today because that is what we know best.

Once you have your strategy set up on Tradingview, you want to start from the most recent candle and go backward in time. Look for your buy signals. Once you find your buy signal, set up a “Long Position” and adjust the middle to be where you would’ve bought if you saw the sign to buy. The top and bottom of the long position are your exit signals. In our example today, we used risk to reward ratio of 1.5, so we would exit when it either hit the top of the green with a profit or come out with a loss at the bottom of the red. 

Backtest a Trading Strategy Long Position Example
Long Position Tool
How to Backtest a Trading Strategy Long Position Example
Long Position Tool Example

As you can see in this example, the long position indicator shows that it would have sold in the green, which means we made a profit. Also, we came out with a 5.86% profit which means I would take our initial investment, let’s just say $1000, and multiply that by 1.0586 (105.86%) to get the exit amount of $1058.6, which means we made $58.6 on this trade, great! Now you want to put down this data into your spreadsheet as a single trade. Keep going until you reach a number where you feel comfortable drawing conclusions from your data about the strategy’s success.

How to Backtest a Trading Strategy Long Position Win Example
Long Position Win Example

Do more backtests than we did. In our example today, we ended up doing 20 backtests just for practice. We recommend you do more, however. We ended up having 15 wins and 5 losses, resulting in a 75% win rate with a super trend strategy. We will provide the strategy at the end if you wish to give it a go. Our results are not enough data to call it a great strategy yet.

Our Backtest Results

Trade #InOutNetWin/Loss
1$1,000$965.50-$34.50Loss
2$1,000$1,058.90$58.90Win
3$1,000$1,054.30$54.30Win
4$1,000$1,048.40$48.40Win
5$1,000$1,058.60$58.60Win
6$1,000$1,067.20$67.20Win
7$1,000$1,047.40$47.40Win
8$1,000$973.00-$27.00Loss
9$1,000$1,040.60$40.60Win
10$1,000$965.60-$34.40Loss
11$1,000$1,071.20$71.20Win
12$1,000$1,041.00$41.00Win
13$1,000$1,049.70$49.70Win
14$1,000$970.00-$30.00Loss
15$1,000$1,065.00$65.00Win
16$1,000$1,074.40$74.40Win
17$1,000$1,078.30$78.30Win
18$1,000$1,076.20$76.20Win
19$1,000$1,071.40$71.40Win
20$1,000$951.90-$48.10Loss
Totalxx$728.6075%
Our Backtest Results

Takeaways from Backtesting

When we did our backtest for this article, we used a super long timeframe of 4 hours. When making such slow trades, you sometimes get in positions for days, but the profits are also more significant on those timeframes. If you were to trade on, let’s just say 30-minute timeframe, you might get more trades, but they will have a smaller amount of profit. So testing your strategy against different timeframes is also essential. Sometimes you will find out that some strategies work better on smaller timeframes or larger timeframes.

Another benefit of backtesting is that you understand what to expect when trading with real money. The data will help remove the emotion from the trades because you know the possible outcomes in the situation. You will also increase the chances that you will not FOMO (fear of missing out) into trades. Having confidence in the system is essential because you do not want to enter or exit trades irrationally. Having trust in your system is a must and having the data to back it up helps build confidence.

Seeing the trades on the graph will also help you understand what kind of trade sizes you should take. During our testing, we had multiple occasions where the positions would overlap. You always need to reserve money for this occasion, and you can gauge how much that should be – you should not let opportunities pass.

How to Backtest a Trading Strategy Overlapping Trades Example
Three Overlapping Trades

The Strategy

The strategy we used during this article is not ours. We found it and decided it would be a perfect opportunity to see its potential by testing it for this article. This strategy is from a YouTube channel called “Trade Pro,” and you can find the specific video for the strategy here. We made some slight modifications to how the indicators look like but otherwise, it works the same. 

While trying this strategy, you might run into one issue: TradingView only allows three indicators when using the free version. The youtube video uses five indicators. We got around this by finding an alternative super trend indicator that has all three lines together. If you do not have paid TradingView, look up the indicator “Triple Supertrend” by “legroszach” and apply the settings that you can see in the YouTube video. You should now have the same layout with fewer indicator slots taken up, but instead of using five indicators, you will be using three. 

By using this strategy, understand that we’re not responsible for any losses you might incur. We’re not financial advisors. This article is just our anecdotal experience. Nothing here should be taken as investing advice.

If you would like to buy some crypto, we have a guide that explores various ways of acquiring crypto today.