How To Test Patterns with Trading Systems (Example + Test on Engulfing)

Need More Help? Book Your FREE Strategy Session With Our Team Today!

We'll help you map out a plan to fix the problems in your trading and get you to the next level. Answer a few questions on our application and then choose a time that works for you.

BOOK YOUR FREE STRATEGY SESSION NOW >>

How can you understand if a technical analysis pattern is effective?

In this video, we show you the procedure to check the effectiveness of a price pattern using trading systems.

To illustrate the process, we created a trading system based on a well-known pattern and tested it on a portfolio of stocks.

We used the Engulfing Pattern, which is one of the best-known price configurations in technical analysis. 

In this video, you'll learn: 

-       How to recognize and code the Engulfing Pattern in MultiCharts and TradeStation 

-       How to evaluate and optimize its performance 

-       On which markets you can use it and on which ones you should avoid it (and why)

Enjoy!

 

Transcription

Hey everyone, welcome back! I'm one of the coaches of Unger Academy.

And today, we're going to see together the Engulfing Pattern, which is one of the most famous patterns deriving from classical technical analysis and, according to the trading handbooks, it's also one of the strongest.

So let's start with our video and see what the Engulfing Pattern is and how it works.

The engulfing pattern

First things first, there can be two kinds of Engulfing Pattern: Bullish and Bearish. In both cases, we have one bar whose body - which is the difference between the open and the close in absolute terms - is greater than the body of the bar that precedes it. And as you can see from the dotted lines in this picture, the body of the reference bar totally incorporates the body of the previous bar.

We have a Bullish Engulfing when a red bar is followed by a green bar, so when a bar in which the open is greater than the close is followed by a bar in which the open is less than the close. And vice versa, we have a Bearish Engulfing when a green bar is followed by a red bar. That's it.

In trading handbooks, it's written that this pattern doesn't need any confirmation. However, its effectiveness could be improved if we came from a downtrend in the case of a Bullish Engulfing or from an uptrend in the case of a Bearish Engulfing. Let's go and see it on the chart. Here, I have highlighted a downward price inversion that indicates a Bearish Engulfing. And if we removed the highlighting, we could see that this bar has a body that covers the body of the bar that precedes it, which indicates a trend reversal. We come from an uptrend and, here, there's a downtrend that's about to start.

Okay, let's also see an upward price inversion now, so a Bullish Engulfing... and here it is. In this case, we come from a downtrend. This candlestick is a green candlestick that indicates the start of an uptrend.

Coding this indicator is very simple because the functions that identify the Bullish and Bearish Engulfing patterns are already present in most trading platforms.

The plot on the chart

Here you can see the code that tells the platform how to plot these patterns. Don't pay any attention to all that stuff, which simply tells the machine how to color and plot the bars in the chart.

Let's just focus on one of these two functions. Let's go open it, and here we can see the conditions used to identify a Bullish Engulfing. So we have the conditions related to the close and the open that define the two bars that characterize this pattern. And then we see this other condition based on a simple moving average that indicates if we're coming from an uptrend or a downtrend.

In this case, we come from a downtrend since the simple moving average calculated on the last 'N' periods, "Len" in this case, is lower than the same simple moving average that was calculated one bar ago.

Alright, so now we're ready to build our strategy and test the real effectiveness of this indicator.

The strategy

This is the strategy, and as you see, it’s pretty simple. So here's where the Bullish and Bearish Engulfing patterns are defined. Then, before the entry conditions, I added another condition that tells me how big the body of the last bar is, so the body of the second bar of the Engulfing pattern, compared to the average of the bodies of the last 5 bars. Then I entered a parameter that lets me multiply this value. If we don't want to use this condition, we can simply set "body_mult" equal to zero.

And here we see the entry conditions. For now, we will make only long entries because I want to show you how this strategy works on a portfolio of stocks. And finally, here we find the exits. In this case, I've set a very simple time exit after N bars.

Backtesting and optimization

We'll backtest this strategy using MultiCharts Portfolio Trader. So let's run the test and see what this strategy would have done on our portfolio of stocks. And this portfolio contains some pretty popular stocks that I’ve picked from the most traded ones that are listed on the Nasdaq.

First things first, we'll define the Engulfing pattern using 5 as an input for calculating the moving average. We'll also use a temporal exit after 4 days and set "body_mult" equal to zero to disable this filter.

So let's go and backtest the system... And as you can see, the first results we get are not so beautiful. Yes, it starts to rise at a certain point, but we see that it fell sharply in 2008. And really, it doesn't seem to be that promising. It has earned about $80,000 since the beginning of the backtesting period, which started in early 2006. So you see, it doesn't perform very well.

The first thing I'd like to do to try and fix this strategy a little bit, since at first glance it doesn't look very appealing, is go and edit the MultiCharts predefined instructions for identifying the Bullish and Bearish Engulfing patterns. In particular, what I'd like to analyze is the effectiveness of the way in which the two bars that make up the pattern are defined. So I'd like to somehow get rid of this condition. To do this, we can simply comment on these two lines of code and replicate this part of the code by adding it to the condition, so to the Boolean variables called 'BullEngulfing' and 'BearEngulfing'. So we're going to replace this piece of code. And then the part that defines the last two bars. 

Okay, so let's compile the strategy and go and see the backtest results again. In this case, we're only going to consider long entries even if we've just changed the conditions for both the long and the short entries. But as I've already told you, since we're testing the system on stocks, we test the effectiveness of this two-bar pattern only with the long trades. 

As you can see, the total net profit has dramatically increased and is now 3 times the profit that we had before. The number of trades is about 400, which isn't a large number, especially considering the number of instruments we're testing. However, it's still acceptable since this is a pattern that doesn't occur so often.

The average trade is around $500-600, which means about 0.6% because we're trading with positions that have a counter-value of about $100,000, so obviously, this average trade is not very large.

The equity line has improved, especially in this part of 2008, when it no longer loses as much as before. However, even if now it goes up, it still doesn't look that great.

So what can we do to further improve it? Well, we could try using the filter we built for the body, so the one that evaluates the significance of the reference candlestick used to create the pattern. And to do that, we could run an exhaustive optimization of this parameter from zero to 2 in steps of 0.05. So we'll get exactly 41 different strategies.

And here's the optimization report. And this time, I'd like to show you a graphic version of the results. The purple line represents the number of trades, and obviously, it's a decreasing number because the more strict the condition we use, the smaller the number of trades made by the system. Let me show you that condition again: we need to consider the body that is greater than the 5-period simple moving average of the bodies multiplied by a certain value. So if we multiply the moving average by 2, the system will make less than 100 trades. And of course, if we don't apply the filter, it’ll make those 430 trades we've just seen.

So, back to the results, the green line in this chart represents the net profit. And what's interesting about this line is that it also decreases and somehow follows the trend of the number of the trades, which means that the average trade remains more or less constant.

And let's take a look at the drawdown, which is represented here by the red line. There's more turbulence here, but I wouldn't think about it too much as it could be just a random combination of events, although a pretty unfortunate one in this case. 

Anyway, these results make me think that this filter can't do much to improve the strategy. The reason why I’ve shown it to you is that I wanted to show you a way to search for edges in the markets and evaluate how effective they can be in your strategies.

Further considerations

And I'd also like to make a couple of remarks about this pattern. The first one is about its very nature. You see, to use this pattern effectively, the close and the open need to be separate. And this can only happen in markets in which the close is more or less distant from the open of the next session. 

So take the crypto market, for example. In that case, the market is open 24/7, so having a clear and substantial difference between the close and the open of the next session would be quite difficult. Vice versa, in the case of stock futures such as the Mini S&P 500 future, even if the future's market is open 23 hours a day, we can still use it. In fact, we can simply cut the session of the future and trade it only when its underlying is open, that is, when the stock market is open, so from half past nine to four, New York time.

On the other hand, the second remark I'd like to make relates to how this pattern is built. We have identified the Engulfing Pattern as a combination of two candlesticks, but what about the sum of these two candlesticks? What does it produce? Will, it produces a Pin Bar, and we've already spoken about Pin Bars in another video, so I give you the link to that video at the top right of the screen so that you can go and watch it.

Now the trading tip I want to give you with this video is that sometimes it can be very useful to go and analyze these patterns from a different perspective, for example searching for an Engulfing Pattern through a Pin Bar and maybe using a different timeframe …I mean, why not?

So as you see, we can start from an idea we find in trading books and explore what we read there in greater depth, breaking the ideas down, testing them in a concrete way, and evaluating their efficacy through numbers. To do this, we use a method developed by Andrea Unger, the only 4-time world trading champion with real money. And with his method, we manage to run these tests and analyses very efficiently.

If you want to learn more about what we do at Unger Academy, I'm going to leave you a link below in the description of this video. It'll take you to a completely free webinar that will introduce you to the world of trading systems and give you a general smattering of the systematic approach to the market and how it works.

With that thank you for watching this video. If you want to learn more about other topics, please write it in the comments.

Until our next time. Stay safe everyone, bye-bye!

 

Need More Help? Book Your FREE Strategy Session With Our Team Today!

We'll help you map out a plan to fix the problems in your trading and get you to the next level. Answer a few questions on our application and then choose a time that works for you.

BOOK YOUR FREE STRATEGY SESSION NOW >>
Andrea Unger

Andrea Unger

Andrea Unger here and I help retail traders to improve their trading, scientifically. I went from being a cog in the machine in a multinational company to the only 4-Time World Trading Champion in a little more than 10 years.

I've been a professional trader since 2001 and in 2008 I became World Champion using just 4 automated trading systems. 

In 2015 I founded Unger Academy, where I teach my method of developing effecting trading strategies: a scientific, replicable and universal method, based on numbers and statistics, not hunches, which led me and my students to become Champions again and again.

Now I'm here to help you learn how to develop your own strategies, autonomously. This channel will help you improve your trading, know the markets better, and apply the scientific method to financial markets.

Becoming a trader is harder than you think, but if you have passion, will, and sufficient capital, you'll learn how to code and develop effective strategies, manage risk, and diversify a portfolio of trading systems to greatly improve your chances of becoming successful.