Transcription
Hey traders, check this out. Here's a script I wrote today. It is a strategy script, very simple strategy. All it does is buy and sell daily breakouts. So, when a new day begins, run the one-hour time frame. Here, the script places a buy stop order three pips above the previous day's high with a five pip stop loss and a ten pip profit target. And then the opposite for shorts. So, we place a three pip sell limit below the previous day's low with a five pip stop and a ten pip take profit. And using a fixed position size, over the past 773 trades, we've had a 46% win rate with a 2.1 risk reward, a only three percent max drawdown, and a return of 157%. It's pretty awesome, right?
What if I told you this script might not be profitable at all? [Music] I think it's time we talked about the TradingView strategy tester system and its dangerous limitations. This lesson is going to be very important, especially if you're new to PineScript. So, what's going on here? And what do I mean by this script might not be profitable at all when it clearly is, looking at the data here? And this is just using a fixed position size. We're not even adjusting our risk per trade based on a percentage of our account balance. We're just trading a mini lot over 773 trades. What could be wrong about this system? Look at all these winning trades we have here. Uh, here's a winning trade, here's a winning trade, here's a losing trade, here's a winning trade, and another winning trade. In fact, there are hundreds of winning trades here. But are they all really winning trades?
Let's have a quick look. If I turn on my drawing tool here, you can see my vertical line here on this bar right before this trade here. We're on the one-hour time frame. And as I mentioned at the start of this video, this strategy is placing a buy stop order three pips above the previous day's high in the strategy tester system. And you can see right here that the strategy tester has counted this long trade as a winning trade. But you might be alarmed to know that this was not a winning trade at all. This was, in fact, a losing trade. And I'll show you what I mean. So, let's turn off this script and drop down to a 15-minute time frame and have a look at what actually happened here. So, here is the trading question. Let's zoom in a bit here, make this a bit bigger. So, let's look at what happened here. This purple line is three pips above the previous day's high. And then on this day, you can see price rallied higher and higher, and then it filled us on our buy stop on this wick here. But then, either on this bar here, the bar that we entered on, price retraced and hit our stop loss. We'd have to go down to a five-minute time frame to verify whether or not this entry bar triggered our stop loss. But certainly, the next bar has a giant wick that went well below our stop loss, which means price actually rallied, filled us, stopped us out, and then hit our one-hour time frame profit target. But we go back out to the one-hour time frame, unhide our script, and go back to this trade. You can see that the strategy tester system has counted this as a winning trade. The problem here is pretty obvious. We have no idea how many times or how frequently this situation occurs. And over 773 trades, I'd say there's a good chance it occurred quite a few times. And I'm sure that the actual results of this strategy, if we were to manually go back and backtest every setup accounting for that lower time frame price action, the results of this strategy would be far, far worse than what the TradingView tester system is telling us.
So, what does this mean? Does it mean that we cannot trust TradingView strategy scripts? In a word, yes, it does mean that. But it's a little more complicated. Not every script is going to behave this way. Depending on how your script detects entries and actually executes trades, that will affect, uh, how susceptible it is to this intraday price action dilemma. Now, the backtester system, when dealing with historical bars, does not account for how price action unfolded within that bar, which is extremely unfortunate. And I wish that the tester system did account for that. It would be great, and it would make a lot more sense if every historical bar on our price chart was calculated using tick data. So, it would play out, it would simulate how that bar played out during that hour, that trading session, and then it would correctly stop us out on our entry candle. But unfortunately, at least in its current iteration or current state, the tester system does not account for intra-bar price action. That is a huge limitation of the backtester system and something you need to be aware of when you are testing scripts through it. Basically, you should be extremely skeptical of the backtester system's results on any script that you run through it. But especially scripts like this one, which use a buy stop and sell stop price to enter its positions. The reason that buy stops and sell stops are particularly troublesome is for the reason I just showed you here, in that we don't know how this bar, this entry bar, played out inside the bar. So, on a lower time frame, the tester system doesn't account for that pullback after our order was filled. One way to mitigate this issue or make it a little bit less of a problem in your scripts is to make your strategy scripts only operate or make its trading decisions based on candle closes. That is one way to [Music] prevent this from being as big of a problem. It can still be a problem if the bar that hits your take profit also tagged your stop loss. It's impossible to know which order that happened in. It's impossible to know if the intraday, intra-bar price action came down and hit your stop loss before it came up and hit your profit target. And the tester system might record that as a winning trade when, in fact, it was a losing trade. But at least if you're operating based on candle closes, that accounts for the intra-bar price action. When you're using buy stops and sell stops to enter your trades, it doesn't account for intra-bar price action, which can be a big problem over a large sample size of trades.
In all of my videos in dealing with the TradingView strategy tester, I always encourage traders to manually backtest their systems anyway of their strategies. Always manually backtest your strategies. There is no way to shortcut this process. The only thing this TradingView strategy tester is useful for is identifying markets and trading strategies that exhibit potential to be profitable. So, just because this trade here was actually a losing trade and was recorded as a winning trade doesn't mean that that happens frequently enough that this entire strategy is unprofitable. It might be profitable, but I can guarantee you that its drawdown and its win rate are going to be significantly different to what this tester system is telling us it is. So, the purpose of today's video is not to scare you off using the strategy tester, but to inform you on how it actually works, what its limitations are, and to warn you against trading strategy scripts based on the tester results. If you were to go out and try to trade this strategy without manually backtesting it first to confirm that it is, in fact, profitable, you're going to be in for a rude shock when you realize that its drawdown is much higher than three percent and its win rate could be much lower than 46 percent. Anyway, that's all I really wanted to say today. Uh, this video is just like a public service announcement of sorts, just to let you know to be dubious of the tester system. Don't depend on it. Don't go out and trade scripts just because this thing says it's profitable. The strength of PineScript isn't its backtesting capabilities, it's its tool creation capabilities. And the indicator, this indicator that we've created here, could make for a great backtesting tool. But as a strategy, I just wouldn't, I wouldn't use it. I wouldn't pay any attention to this information whatsoever until I manually backtested this using an old-fashioned spreadsheet and hours of hard work. Unless you're going to commit to learning a language like MQL or Python or something more advanced than PineScript, uh, don't depend on PineScript to replace the role of manual hard work in your trading process. It's just not going to happen. It can dramatically speed up that process. For example, let me throw on a script that I am working on currently. Here is a script that I created that is actually profitable. I have gone back and manually backtested this, and it is profitable. But these numbers here are not accurate. Uh, the win rate was a little bit lower, the drawdown was a fair bit higher, nearly double, and the net profit was around the same, I think, if I remember correctly. But this system, this script, operates on candle closes. And the whole purpose of it isn't to replace my backtesting process, but to help me in that process, help me speed it up, be more efficient. You can see that this script actually draws my stop loss size and my take profit size directly onto the chart, which helps me backtest markets significantly quicker than if I had to manually add on the ATR indicator and measure from the closing price to the low and add the ATR onto that number to get my stop loss. Forget about it. I'm never going back to doing that manually ever again.
Even though I wouldn't depend on the strategy tester system, um, it's not a waste of time. This script does help me identify markets that are more profitable than other markets. For example, Eurocad here is not very profitable at all, and I haven't manually backtested this yet, but I assume that if I did, my results would not be profitable either. But on some of these markets, this strategy does show potential. And so, to summarize, I'm not making this video to scare you off the backtester system, just to inform you not to trust it completely. Make sure to do your own research, do your own homework, and just use the tester system to help you identify markets that might be profitable so that you can prioritize them in your manual backtesting process and save yourself time from testing all of these markets one by one. You might give up testing a strategy that is profitable because it wasn't profitable on the first five markets you spent weeks backtesting using this backtester system. You can identify markets that might show potential on certain strategies and then you can confirm that potential by going through the process of manually backtesting, entering that data into a spreadsheet to get a more accurate sense of its total gain and max drawdown and its win rate. Wherever that is here, let me change that to percent. So, a 43% win rate with a two-to-one risk reward is still profitable. But this isn't what my script was telling me. My script said that it had a 50% win rate with a much higher return. But this strategy was still profitable on this market, at least in theory. Even your manual backtesting doesn't account for things like slippage, spread, commission costs, missed trades that you couldn't take for whatever reason. You've all seen the disclaimers: historical performance is not indicative of future performance. That's true for automated backtesting results as much as it is for manual backtesting results. But in saying that, historical performance is the only indication we have of whether an approach to trading has worked in the past. And the only way to truly confirm that the strategy you want to trade is profitable is to forward test it with a small account balance, a small amount of risk. A lot of traders recommend demo trading a strategy. If you're an experienced trader, I wouldn't bother with demo trading because it doesn't account for commission costs, it doesn't account for real market conditions. If you're a beginner trader, of course, demo trading is important so that you can learn your platform, learn how to trade, and learn the process of trading. But if you're an experienced trader who is profitable, or at least isn't blowing accounts, and you know what trading really is about, uh, then forward testing on a real money account with a few hundred dollars is the only way to truly confirm if a strategy can be traded profitably. Just because it's profitable in theory doesn't mean it will be in practice.
So, that's it for today's lesson. If you want to learn more about strategy scripts or how to build trading tools to assist in your backtesting process and your live trading process so that you never miss trades, you can automatically generate alerts for trading setups that you trade. So, if you already have a profitable strategy, coding it in PineScript is one of the best things you can do because even though it might not be able to backtest for you, it can help you trade more efficiently, it can help you test more efficiently, and it can help you to never miss a trade ever again. So, if you'd like to learn more about Pine, or you want to steal the source code, every script I've ever written, including a few profitable strategy scripts that I've manually backtested to confirm that they are indeed profitable, head over to pinescriptmastery.com where you can find all of my courses on PineScript, including a free basics course if you're new to this and you just want to dip your feet in and just sort of test the waters a bit and see if this is something you'd be interested in. Anyway, that's it for today. Thanks for watching. Good luck with your trading. Take care, and beware of the TradingView strategy tester. Don't trust it. Don't trust anyone or anything in trading. Always manually backtest. Do your own research. Do your own forward testing. Uh, do your own work. No one can do your homework for you. It pays off in the long run. It is hard work, but it's worth it. See in the next video. Goodbye. Yes.