How To Backtest Your Strategy In Tradingview
The Daily Edge

How To Backtest Your Strategy In Tradingview

Authored by Ivan Delgado

Ivan Delgado is a decade-long Forex Trader. Feel free to follow Ivan on Youtube. Join thousands of traders who follow Ivan's insights to increase their profitability rate by learning the ins and outs of how to read and trade financial markets. Ivan has you covered with in-depth technical market analysis to help you turn the corner.

n

So, I suspect you are aspiring to make a living out of your trading? No? Fine, too ambitious. Perhaps you just want to supplement your daily job salary with a side-income?

Whatever the reason, you must understand this, and excuse my boldness… You stand no chance! Unless, of course, you have thoroughly backtested your strategies.

I know, I hear you. You must be thinking, but Ivan, what’s the big deal about backtesting?

Why is this impossibility of success without knowing inside out your strategy such as indisputable truth? 

Brace yourself for another reality check… This article will open your eyes.

First of all, by backtesting a strategy, you avoid the common pitfall of letting the short-term results determine your level of commitment towards your strategy. This is massive to not see yourself in a vicious loop of what’s often referred to as ‘system hopping’.

Whenever one goes through a cluster of bad luck (losing streaks), that’s when ‘testing times’ come to stick with unshakable conviction towards the strategy ‘you own’.

But due to human nature, guess what happens? 

We let short-term results justify that time has come to ditch the existing strategy and seek out yet another way of trading with the elusive thinking that losing streaks may be avoided. No backtesting a particular strategy is a receipt to fall victim of this perpetual cycle.

If your aim is to build confidence in a strategy that will act as your coerstone and the trigger mechanism to enter into trades, there is no shortcuts. I wholeheartedly am a proponent of going through a rigorous process of backtesting it to determine if it has proven to be profitable over a large enough sample of trades.

With that said, in this article, I will walk you through the process I follow in backtesting my setups.

Manual or Automatic Backtesting?

Now, there is going to be the camp promoting an automatic approach, while others, including myself, have an inclination for manual backtesting. There is no right or wrong, just a matter of preferences, and well, also the fact that certain strategies may not be as easily programmable. 

Since I’ve always interpreted any tradable instrument, through its price action fluctuation, as psychology in motion, to me it becomes more an art than a science to trade them, even if I completely recognize that the market is gradually shifting towards a machine-dominated terrain.

But my point still stands. Personally, I’ve always loved manual backtesting because it requires one to study the charts and ‘changing’ conditions (this is a big one) and simulate trades according to certain factors that you observe ‘in situ’. Moreover, your brain can build new neuro-pathways in tune with what you see and trade. 

Automated backtesting works on a code so that means that the user must stipulate in detail all the functions to be called to begin an arduous jouey of fine tuning parameters to hopefully get to some optimal results. Totally respectable but not my cup of tea quite frankly.

What Charting Software I Use For Backtesting?

So, first I will go through the platform I use to backtest my strategies. To me, hands down, Tradingview is the winner here for a variety of reasons such as reliability, familiarity as it’s the charting software I also use to run my daily analysis, in-sync chart functionalities, large historical data sets, etc.

My backtesting template looks like the illustration below. I split it into 4 charts, with the Weekly, Daily, 4-hour to assess the market conditions at the time of taking the trades off the top left chart, which shows the 30-minute chart, in this case, on the EUR/USD.

My settings include replicas of the Symbol in display in all charts, visibility of the crosshair placement across all charts, and in-sync time, which is key to always understand under what type of market dynamics in higher time frames I am taking the trades.

After that’s been setup, the next step is to go back to the start date you’d like to begin your backtesting. As a rule of thumb, I always tend to go through sets of yearly data variables. That means each tab on my spreadsheet will correspond to a market and year.

If one wishes to conduct backtesting from let’s say early 2019 until the present days, below is how you set it. You simply click on ‘Go To…’ and a popup window will allow you to input the date. Then just click on the blue box and you will be redirected to the specified date.

It should only take a few seconds until all your charts get reset and in-sync from the date selected, in this case, January 8th, 2019. From there, I start testing the strategy off my trading timeframe (top left) while keeping track of the conditions in higher time frames.

The in-sync crosshair across charts makes it very intuitive to visibly locate at what point in time a trade would have been filled in the context of higher time frames. That’s key because you want to take notes of the market conditions in the bigger picture. 

Joualing Your Backtesting

That’s the part that has to do with the manual backtesting. However, it would defeat its valuable purpose unless one can start collecting data to come to certain conclusions. That’s why, joualing your backtesting is key to provide the necessary insights to finetune the strategy.

See below what my google excel spreadsheet looks like. As one can notice, it’s designed to register all the inputs that I am interested to study as part of refining a trading edge.

In my case, I include the date, time, direction, type of entry, then in grey a series of factors I want to account for when taking trades such as price structures and moving average slopes in different timeframes, and a few others. I also want to obviously detail the outcome of each.

As part of the yellow-filled cells, I’ve always followed the same logic. Did price hit my stop for a loss, ended at break even or went for a winner? But there is more to it. In case it went for a winner, what was the max risk reward potential with a 10:1 as cap.

Also, how much of a drawdown did I experience on the trade? If the drawdown is far from the 100{c55dae091e2f4b96c42546a5edb68ce9f701c78980adb8fd55b74e573b5f59f6} mark, which would equate the stop got hit, the more evidence one can obtain that the stop loss placement can probably be shortened to aim for a higher risk reward.

Below I provide the same joual, but this time, with the sample of trades logged in the EUR/USD market during the year 2019. Notice that I also include a ‘remarks’ section at the top? That serves to throw my ruminations and observations based on the data gathered that year.

As I keep collecting more data year after year, these annotations on the subtleties that I observe can be isolated and studied in detail in order to understand how each one is affecting the results of the strategy. These insights are priceless to refine my trading approach for optimal results.

During the manual backtesting, every trade taken is screen-captured and the image file saved into a folder with the name of the market and its corresponding trade number. I’ve now put together a collection of thousands and thousands of charts that I study to expand the wiring and memory of my brain as it relates to the intricacies of the setup. 

This way you ‘own’ the setup. This wiring of your brain thanks to the repetition of taking the same setup over and over builds new neuro paths, which is a concept that falls under the area of study called Neuroplasticity. It is described as the brain’s ability to change itself constantly by creating new neural pathways. 

For the brain to rewire itself it requires sustained practice of a new behavior which will sufficiently challenge the brain to think in a new way. That’s what manual backtesting foes to our brain as it relates to the strategy that we aim to program and trade almost subconsciously. 

In sports, you do drills to create muscle memory, so you can instinctively act when the time is right. To me, the drills in trading are the backtesting, including the screenshots attached. In fast moving market conditions, the more practiced a strategy, the more I am able to implement the skills that I have been training for when the time is right. 

Below is the EUR/USD folder screen-capturing a sample of all the trades of 2019 as shown in the joual.

Wouldn’t you find it tremendously valuable to identify under what set of circumstances you tend to make the most retus? Joualing your backtesting, at the end of the day, acts as a filtering mechanism to access insights on what’s working and what isn’t as part of your strategy. You then are better informed on what to remove and/or reinforce.

You must continue to constantly tilt the balance towards actions that are going to be conducive in eliminating unnecessary losses while working on those that bring the most reward. A trading joual as part of your backtesting (and real trading of course) is an excellent tool to reveal a huge amount of valuable information.

Now, if you wonder, how extensive this backtesting has to be? Personally, the more the better. If you trade off the 30m chart, it’s really all about how many trades your setup shows up in a particular year. In my opinion, the bare minimum should be 100 trades per market to have a rough initial estimate. 

Ask me anything about my signature setups, and I will tell you the numbers. Times that it gets triggered per year? From 25 to 40 times, which equates to once every 7 to 10 trading days. But that’s just one market, as I add more instruments to trade, the tradable opportunities expand. And so forth… 

If you are serious about trading, the backtesting process should be ongoing. It will take weeks or months of repetition to obtain sufficient data. The longer the in-sample, the more robust your statistical edge can be, which leads to increased conviction upon its expectancy.

From Backtesting to Demo to Live

After one is able to gather enough in-sample in a particular market, the next phase I would recommend, especially for newbies in the market is to trade the strategy on a demo.

This time, however, forward-testing it to know what’s like trading the strategy with real-time data yet no risk of unnecessary money lost due to lack of experience.

You should stay on a demo account for as long as necessary until your results start being more consistent and lea to control your risk adequately. The more you forward test it, the more room to further optimize the strategy while still gaining further exposure and experience.

One of the reasons I recommend taking this demo to Live steps is because placing actual trades under real market conditions risks deviating from the simulated performance graph significantly. 

Why, you may be asking? What’s preventing you from mimicking the backtested results? Your psychology. Once emotions get in the way, a plethora of reasons from fear of losing, fear of pulling the trigger, revenge trading, etc, kick in, taking us off course.

That’s why it cannot be sufficiently overstated that trading without mastery of your psychological aspects is a futile exercise. But similarly, having an excellent psychological control without the conviction of applying an edge also defeats the purpose. It’s a holistic approach, and the mental part, I am afraid, goes beyond the scope of this article.

However, don’t forget that in the past, I’ve written articles such as ‘The Samurai Principle’ that will help in giving you the right perspective of the mental game we play.

Also, be aware that creating a great system based on old data gives a limiting scope of the true potential of the system into the future. The reason is because markets are constantly changing, so there is no guarantee that the market conditions you’ve tested your data under will stay.

There is definitely a well founded truth in the saying that “Past trading performance is no indicator for future trading results”. But by manually testing one strategy, you can certainly circumvent some of these limitations as you can take note of the environment traded in detail.

The key point to consider here is the fact that the market will not always behave in a similar way and this is the reason why we need to test the trading strategies on various market conditions so that we know how the strategy will perform in those conditions.

Once you’ve built enough confidence and you start seeing the results on your side, give yourself permission to go live with minimal capital on the line starting from as little as 0.1{c55dae091e2f4b96c42546a5edb68ce9f701c78980adb8fd55b74e573b5f59f6} risk, and gradually increase the risk in marginal weekly steps if results prove profitable during this period.

Take Ownership Of Your Strategy

To me, and it should resonate to the reader too, this fancy word of ‘backtesting’ hides behind a more important meaning, which is, taking real ownership of your approach as a trader.

The moment I came to terms in adopting a style that not only resonates with my personality but that I could single-handedly determine what is it that constitutes the edge, based on thousands and thousands of hours observing the market, that’s massive.

Being the owner of your destiny starts by making your own decisions, hence, why you must take ownership of how you are going to be trading the markets with purpose and authenticity. Manual backtesting opens the doors to building up neuropaths necessary to build up your confidence as a trader knowing you are applying a strategy backed by past data. And while this is far from any guarantee, your odds of success will definitely increase. 

n