The Strategy Tester Explained: Tutorial
https://www.youtube.com/watch?v=7rZ2DZkelVo
Transcript:
Let’s talk about the strategy tester. Now, the strategy tester can be found at the bottom of your chart. Check out our mouse hovering down here at the bottom where it says strategy tester. You’re going to want to click that and now you’ve opened the strategy tester. The next step is to load a strategy directly onto the chart.
Strategies are essentially trading or investing that has been coded onto the chart so that you can now see how that strategy would have performed over time. So let’s take a step back there. Let’s talk about the importance of the strategy tester and what it means to you as an investor or trader.
Every investor or trader on the planet has a different time frame in mind, a different style, a different technique, a different way to analyze markets. However, every investor or trader can go back and back test how that strategy would have performed. And that is where the strategy tester is really important.
This is raw data on the chart that you are going to be able to see, and you can evaluate how you would have performed with a specific strategy going back in time to some of the most volatile and important moments in market history. For example, we all know what happened in 2020. That was COVID-19. And what happened after COVID-19 was one of the greatest and most volatile moments in market history. There was a fairly large crash in 2020 during COVID.
Well, how would your strategy have performed during that time? Let’s find out. So we’re going to click load your strategy. Now, every strategy is coded in Pinescript. So you want to master the indicators, metrics, and strategies menu, because here you can find technicals such as indicators and strategies. You can find financials.
So if you’re interested in charting things like total revenue or cost of goods sold or gross profit, you can also find community scripts. These are coded by investors and traders around the world. Some of them even code up strategies that you can test on the chart yourself.
For the sake of of this video let’s click strategies because that is what we are focusing on and remember in this menu you can always tell if something is a strategy because it will have this icon here it sort of has a chart with a down and up arrow this is a strategy now let’s pretend we are a trend trader and we want to trend specific trends. So we’re going to use the super trend strategy.
And if we wanna learn more about the super trend strategy, we just click this little question mark that says show description and we can read about it, including its inputs and what some of the definitions are about this strategy. So we’re gonna click super trend and it’s been applied to the chart. And now we can see tons of data and advanced visualizations to better understand how this strategy would have performed.
So once again, let’s say you are a trader and you want to see how your strategy would have performed over time this is one of the best ways to back test that now you are going to have to know a little bit of pine script well if you don’t know what pine script is or if you’re a beginner or maybe you’re an advanced training view user and haven’t yet explored this all of the indicators and strategies are written in pine script and you can see that there’s a little source code icon here with brackets go ahead and click that now as you can see the pine editor has opened
up and here is the pine script this strategy has been coded in pine script that is trading views official coding language you can code up anything or just about anything in Pinescript. Make your own indicator or make your own strategy and then use the strategy tester to see how that would have performed over time.
If you don’t know anything about Pinescript, well, there are three dots over here in the more section. Go ahead and click that. And there’s a user manual when we click to open the user manual this is available and free to all trading view members you can learn pine script right from here it might take some of you a few hours to understand pine script for others it could essentially take days or weeks but either way if you’ve ever wanted to know how to code, say you’re an investor or say you’re a trader and you want to learn how to code, well, this is a pretty incredible opportunity
because you can combine your love for markets with coding and you can do both at the same exact time. Even for example, in this part of the user manual, we can learn about the difference between indicators and strategies, but that’s the point of this video. We are talking about strategies and how to get started with the strategy tester.
So you’re going to want to code up your strategy in Pinescript and then use the strategy tester to see how you would have performed if you traded that exact strategy over time. So let’s even talk a little bit about trading and investing 101. As you know, there are lots of traders and investors out there who think they have found the holy grail to trading or that they are going to make tons of money in markets. But we all know markets are not that easy.
And oftentimes you have to do the hard work, the analysis, the research and planning to really understand how you would have performed over time. That research is to some degree the foundation of trading view. Look first, then leap. And this is one way you can look first in a very rigorous analytical way to really understand your performance so we have the super trend strategy on the chart we are now looking at apple well how would we have performed over time with the super trend strategy we have this beautiful visualization to work with and now let’s walk through the strategy
tester in detail. We have it open and we can see all of the key components here. We can see our net profit. We can see our total closed trades. We can see our percent profitable. We can see our profit factor, our max drawdown, our average trade, and the average number of bars in trades. Once again, if you don’t know what any of these mean, there are tool tips for you to hover your mouse over to quickly learn exactly what these things mean.
Now, how about we talk about the strategy tester and the inputs that go into it for example we know that we have added the super trend strategy to the chart and now that we’ve added it to the chart we can see the long entries we can see the short entries we can see the profit and loss of every trade right here on the chart you can see these red arrows and these blue arrows are the long entries and the short entries. And if we go back in time, we can see how this strategy would have performed.
Where would it have entered? Where would it have exited? And was it a good strategy or a bad strategy? Or even going back to our earlier point in the video, we can better understand how our strategy would have held up in some of the most volatile moments in market history. Let’s even go back to the great financial crisis.
For those who are young and don’t remember it, this is one of the most historic market crashes in recent memory. This is the 2008 and 2009 crash. We have a chart open up here of Apple. How would our strategy have performed during these really difficult crashes? There’s really no better way to understand how your strategy would have performed than going back in time and looking at these incredible volatile moments in market history.
Once again, you have to code that though in PineScript to see it on the chart, or you can use one of the built-in strategies. But essentially what you need to do is write in code what you want to see, i.e. buy under these specific conditions, sell under these specific conditions, and show me that on the chart over time and crunch that data and tell me how it would have performed.
And that, after all, is what the strategy tester is telling you. It’s telling you that if you code up your buy and sell rules, or in this case, the super trend strategy, here are all of the buys and sells that would have occurred over time on the chart, these red arrows and these blue arrows.
Furthermore, here is all of the data being presented to you so you can analyze whether that strategy would have performed really well or really poorly. Now the inputs of the strategy tester are important. We talked about what the columns here mean, net profit, total closed trades, etc., etc., but the settings menu is equally important because after you’ve coded up your strategy or used a built-in strategy, you want to make sure that the strategy tester is set up to your exact specifications.
So if you click the settings menu, now from here, you can actually adjust the inputs. So for this, you can adjust the inputs of the strategy that you’ve added to the chart. We’ve added the super trend strategy and we can change the ATR length or the factor. These are both inputs about the strategy. This is what determines our buys and our sells in this example. Remember, these are all examples.
We are not giving any buy and sell recommendation. This is about doing research so you can make better decisions into the future. TrainingViewue is a research platform after all, and this is an advanced tool to really get some granular data about your process and markets. Now there’s another tab here called properties.
This is what you probably really want to focus on. Once you’ve applied your strategy to the chart, because you’ve coded it in PineScript, now you can actually make some key adjustments to your strategy tester. For example, this is a favorite of ours. This is initial capital. How much capital are you starting with? You can make this be a dream number, $1 million, or maybe a more realistic number for your account, or perhaps a small amount of money.
So if you coded up your strategy in Pinescript or you applied it to the chart, now you can see the strategy tester. You can change your starting capital. For this example, let’s pretend we started with just $1,000. So we are going to say that for this super trend strategy, what would have happened to our initial capital if we only started with a thousand dollars let’s go ahead and click ok you can see now that the strategy tester has changed pretty dramatically you can see down here we would have started with just a thousand dollars at our first trade and here are our trades
over time so this bottom this bottom here is counting the number of trades that are being taken based on the parameters of the strategy that you have implemented. In this case, it’s our super trend strategy. Our super trend strategy is using ATR length and factor to place trades, buys and sells. But of course, you’re going to want to code up your own strategy to test.
Now you can see our trades over time and how just how profitable we would have been. This is fairly interesting because this strategy on Apple would have taken well over 300 trades. And in addition, it would have turned that $1,000 and made a $2,977 profit or 297%, 310 total trades.
So we’ve now seen that in this example, that would have performed fairly well. Of course, there are some key things here. We are just testing the strategy for its viability. and this is just one symbol that we’re testing it on so while you may see an excellent profit here or a great return there are a lot of things to consider before you suddenly say that this strategy is an immediate winner for example you should test it on different time frames keep in mind we are looking at this strategy on a daily chart as well. So you can start to understand just how many variables go
into evaluating a strategy. What time frame are you on? What symbol are you looking at? If we change this to a one-hour chart, say we want to trade this strategy on this one-hour chart, you can start to see that things change quite a bit and actually over a one hour time frame just training this on a one hour chart we are not nearly as profitable as a daily chart in addition if we change the symbol we’ll see this change again and actually even go back to a daily now.
So let’s go to a daily chart. Let’s click one year. Let’s go back to strategy tester. So you can see how would our strategy have performed on a different symbol like IWM, or maybe Netflix, or how about BTC USD, or how about Amazon, or what about another company like Tesla? So you’re seeing all of the trades here based on the symbol and time frame that we are selecting.
These are really important things to consider whenever you test a strategy. Because as we’ve mentioned, markets are oftentimes very complex, and there is no such thing as a quick and easy win in markets. It takes time, research, planning, and process, and the strategy tester is one way to do that. More importantly, you can see how quickly you can test your strategy’s results on different timeframes and different symbols.
on different timeframes and different symbols. So you can really quickly gain a ton of information and insight into markets just by changing the symbol here and watching your strategy tester update. In fact, you could even take the time to go through different asset classes to maybe better understand, does your strategy work better on stocks or does it work better on crypto? In addition, you could take the time to go through different timeframes, weekly timeframes versus daily timeframes. How would your performance have done? Perhaps even
a monthly timeframe. And remember, the reason why the strategy tester is changing based on the time frame that you select is because it is set up to place by and sells depending on some inputs that you have created in pine script so this pine editor and that of course is going to be different depending on the time frame you’re looking at so it’s all about utilizing the strategy tester to understand how you not only would have performed in the past, but also how you would have performed on different time frames and different symbols.
All of these insights are ultimately going to help you make some informed decisions about what you want to trade, how you want to trade or potentially invest, and what time frame you want to specialize on. Do you want to be a trader that has a set system or a set strategy on smaller time frames like a one-minute chart? Do you want to be placing one-minute trades? Look how many trades this is placed in a minute.
Strategy tester so far shows that it is negative on this one minute strategy test or do you want to be zoomed out on a weekly chart taking your time and looking over the long haul these are decisions that the strategy tester will ideally give you some insight into now we have not finished up our tutorial into the settings menu but remember we showed you how to change your initial initial capital there is also so much more here that we want to dive into for example your base currency depending on where you are in the world or what currency you’re trading in you have the ability to test it in a specific currency, whether it’s dollars or euros or anything else
you see on this list. In fact, if you do change it to euro, for example, you’re going to see different results in your strategy tester because now you’re trading in euros, not dollars. So for the sake of this video, though, let’s keep it on US dollars. You can also control your order size and your pyramiding.
And if you don’t know what any of these mean, remember, once again, we have tool tips for all of these items. You can hover your mouse over them to learn more about them. Keep in mind, we also have a help center where you can learn more about these tools. And of course, the comment section on our YouTube channel or even on trading view in our social network you can ask us questions reach out to us write in the comments reach out to other users in our social network to ask them for help let’s also talk about commissions how important
are commissions well commissions are really important because if you’re trading an asset or a symbol that actually takes a commission of every trade well remember that is technically money that’s being removed from your account to pay for the trade so it’s going to dramatically change your the outcome of your strategy so you should really make sure that if you are trading something or on a platform or an asset that takes a commission, you should input what that commission is, whether it’s a percentage commission or a cost per contract or per order. that is technically the money that you could have invested into this symbol that now has to be paid
to a middle person or a broker or something of that sort. And that will reflect in your strategy tester. Most likely your net profit will be impacted to the downside because of the money that you’re then paying for commission. So you want to make sure that you adjust your strategy tester for commission. There’s also verify price limit for orders.
And of course, there is slippage as well. Slippage is something that is sort of a under discussed topic, but is really important to the strategy tester because what slippage implies is that not every order you place will be perfectly filled what exactly does that mean well oftentimes in markets there is not perfect execution there is sometimes a one two three four five cent deviation from what the buy order is and the sell order when you go to execute the trade there is a slight slip in the price so there is a possibility that
you thought you would be filled at one level but actually there was some slippage and it was a it was a different fill based on that slippage if you know what your slippage is or you can sort of estimate what that slippage is on average, you’re also going to want to fill that in as well because it will once again update your strategy tester to reflect more realistic results based on the slippage of your trades.
So what you’re really doing in this settings menu is you are creating an ultra realistic strategy test you are inputting everything that is occurring in your trading process to then give you the most realistic feedback on if your process is profitable or if it’s losing money or if it’s an average average strategy or a fantastic strategy that is what you’re doing here so you’re going to want to fill out this properties menu as realistically as possible to get the absolute best results back in your strategy tester now of course you have margin for long positions. You have margin
for short positions. If you are trading with margin, you’re going to want to fill this out because once again, that will also greatly change the outcome of your strategy tester. And there are a few other important things now about the strategy tester as well, which use you have some basic style functionality here and you also have some visibility options.
Okay, this video now has exceeded 20 minutes, but we’re not even done yet. So we’re going to rush through the final few items here on the strategy tester. Okay, at the bottom here, you can see the checks and now we’ve unchecked all of them so naturally the visual in front of us is blank well what are these checks equity this equity check represents your account it is the equity that you have in the strategy how much equity have you accumulated is it growing or is it falling over time and that is what you see here on this green line. Your equity curve
looks quite positive. Actually, after trade 31, it really started to break out and started to perform well. Drawdown. Drawdown is a really important visual to understand. There is no such thing as a strategy that wins 100% of the time. There will be losses, and that is sometimes referred to as a drawdown.
How much money would the strategy have lost at certain points in time? Some trades will not be winners. They will be losers. And these purple bars here are the drawdown. So they show what trades lost money and what the drawdown was like. So on the left-hand column here is your equity.
You can see the equity curve and what your account balance is growing to or falling to. On the right-hand side here is your drawdowns. So you can read this like your drawdowns. What were your largest drawdowns and what were your smallest drawdowns? Actually, you can see this trade 32 had a $548 drawdown, but the account was still doing quite well based on its historical performance and the equity in it. And of course, on the left-hand side, this is the equity amount.
So you can see it ended with, we can just drag our mouse over here about four thousand dollars in the account and that is where the uh the left scale and the right scale really come into play now buy and hold equity is another very important button to click well why is this important to click we’re we probably should have gotten to this earlier in the video but buy and hold equity is essentially going to show you what the return would have been if you bought at the very start of the back test and just held so you you didn’t you know place uh tons of trades over time and you just bought it and you
held it and that’s all you did well as you can see it’s very clear that actually in this example on apple you would have been better off just buying and holding and watching that accumulate because you’d have close to $1.1 million as opposed to if you were trading it $4,000.
So that is a huge difference and incredibly important to understand because it shows you the opportunity cost. At the same time, keep in mind, we are looking at Apple. So naturally, if you had bought Apple all the way back at its IPO, yes, you would have been doing fantastic. But we can look at other symbols to better understand how that’s not always the case. If, for example, we type in TWLO, you may know Twilio.
We type in strategy tester, now select buy and hold, and you can actually see that your buy and hold is just about 5,200, but it is still outperforming the super trend strategy. There are, as we mentioned earlier, you can really have some informative takes undergoing this process, just walking through symbols and comparing what your buy and hold would be versus your trading strategy but once again one very important thing to remember about buy and hold is on these long-term time frames it assumes for example that you had that you had bought at the IPO and held over 5, 10, 15, 20, 30 years.
Obviously, that’s not always possible. So it’s pretty important to understand the realistic nature of that buy and hold for certain symbols that you type into the symbol search. How many people really bought Apple in 1980 and held it this entire time? They’re definitely out there, but it’s not exactly the easiest thing to do.
It’s probably just as difficult as finding an amazing strategy. And as we look for a symbol to better illustrate this buy and hold example, we can really start to show you what the opposite end looks like if an asset, for example, is below its IPO price.
So here’s PLTR and let’s go to a weekly and well, PLTR even had a somewhat of a big breakout. So let’s go to daily and we’re gonna go here and click buy and hold equity you can see the gap is closing though here a little bit the blue line so the strategy in this example of super trend would have returned about $1,200 and the buy and hold so far is only at $700, only at $800.
So actually this strategy would have lost money on a buy and hold, on a buy and hold basis or relative to the actual super trend strategy it underperformed and that’s an exact example of what we are trying to illustrate is that the buy and hold comparison can be really fascinating when you look at companies like apple because of the temptation to say you could have just bought and held apple through since its ipo but that’s not always the case so So here’s another example. This company IPO’d at about $28 back in 2018.
But we go to the strategy tester. And as you can see, when we do buy and hold, once again, actually buy and hold is underperforming. That’s the blue line versus the strategy, the super trend strategy, which is the green line. So you have to make sure that you are absolutely doing comparative analysis like this.
Buy and hold would have turned the $1,000 into about $250. And if you had followed the super trend strategy on this symbol FTCH, you would have about $1,000. So these are the type of comparative analyses that you want to do. We still aren’t even done with this video and that just illustrates how powerful this tool is because you can click performance summary to dive into the nature of the trade and get even more data about the strategy that you are testing.
You can also see a full list of trades by clicking list of trades and scrolling down. So this list of trades will show you the complete history of the strategy tester, showing its starting point back in 2019 and bringing you all the way up to its most current entry. This video is being recorded in June of 2023, but the strategy only most recently entered a trade in May of 2023.
And then of course, you can get some more details about the properties of the strategy. And you’re going to want to use this page if you’re looking to fact check everything that you are working on we also have a beta beta tool called deep back testing which is slightly more advanced for those who are looking to get really deep into the strategy tester and you can find that, once again, in the Help Center, and you can turn it on by just checking this box.
But, of course, hovering your mouse over the tooltip and clicking it will get you started on deep backtesting. It is in beta, so please give it time. But we won’t go into it because it’s quite advanced, and the more advanced strategy testers out there and pine coders out there have probably already explored it, but you can get started on it just by turning it on.
it should prepare you for the strategy tester, it should prepare you for the need to understand Pinescript, and it should prepare you how to open the strategy tester, how to understand it, all of the help center information that’s available to you, and then of course the power of understanding the settings menu and just how key it is to know the properties menu so that you can build a realistic strategy for yourself.
In addition, we covered what the right scale means here for drawdowns or what trades would have lost money and just how much. And the left side here, which is the growth of your account or your equity curve. And really important is the boxes here at the bottom where you’re able to check and uncheck some pretty key things to better understand the strategy’s performance, like your equity curve, like your drawdowns, which are these purple columns, as we mentioned, and of course your buy and hold equity. So you can compare buy and hold equity so you can compare buy and hold versus your strategy thank you everyone
for watching please ask any questions or comments in the comment section below once again you can also check out our social network you can use our help center you can message our team we’re everywhere on social media we understand that the strategy tester is a very powerful tool with tons of data and information the quick way you can move through various symbols to test out your performance over time and see how you would have have done and especially to check that out on different time frames and it’s going to take some time for you to really master this if you are a new trader but
that’s what we’re here for it’s why we read all of our comments it’s why we take some time for you to really master this if you are a new trader, but that’s what we’re here for. It’s why we read all of our comments. It’s why we’re across the web on social and even have our own social network.