Trading System on Forex: How To Create And Test a Strategy with Pin Bars

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 >>

In technical analysis, especially in Forex trading, Pin Bars are graphic patterns that indicate price inversions.

These bars (or candlesticks) are characterized by a body that is much smaller than the range and can be either bearish or bullish.

This video shows a trading system that sends entry orders when certain Pin Bar patterns occur and tests how it would have performed on Eurodollar and other currency pairs over the last few years.

Watch the video to learn how to code Pin Bars in trading systems and how effective they are! Enjoy! 😊

Transcription

The PinBars

Hello everybody, I'm one of the coaches of Unger Academy and I welcome you to this brand new video. 

Today we're going to be talking about Pin Bars, one of the most famous candlestick patterns out there.

We’re going to explore something related to more traditional technical analysis, let’s say, but in a more systematic way.

First things first, let's see what a Pin Bar is. When we say "pin bar" we mean a bar that has an extremely small body compared to the range of the bar itself.

As you can see, here are three examples of candlesticks in which the difference between the open and the close of the bar is very small compared to the difference between the high and the low. And it doesn't matter if the open and the close of the bar are positioned above or below the high and the low of the bar. All these bars are categorized as Pin Bars.

Candlestick Patterns

Now let's see some patterns based on Pin Bars. The first two patterns that we are going to see are called Hammer and Inverse Hammer. Both of these patterns represent a market reversal. As you can see, we have a more or less significant downtrend that is followed by a pin bar whose body can be either in the higher or in the lower part of the candlestick.

This indicates some indecision in the markets, and this Pin Bar is often followed, at least according to literature, by an upward trend.

The other two patterns we're going to see today are called Shooting Star and Hanging Man. They are symmetrical to the Hammer and Inverse Hammer patterns, which means that we have a predominantly upward trend followed by our reference candlestick, so our Pin Bar. These patterns represent a reversal followed by a downward trend.

Now, since we are systematic traders, and as you know, we love backtesting the behavior of the markets, I decided to code these patterns and try to understand if they can be useful and give us some advantages.

Candlestick Patterns Indicator

So let's move on to the practical part of this video and open the Power Language Editor. As you can see, I have already coded an indicator that can identify these candlestick patterns. To do this, I used an efficiency ratio, which is a value that confirms the presence of trends. This efficiency ratio is calculated in a much similar way to how we calculate moving and adaptive averages.

Then I define my Pin Bar, which can be up or down depending on the pattern, such as the Hammer or the Inverse Hammer.

I analyze the open, high, low, and close values of the bar, so I see if the high minus the lowest value between the open and the close is less than 33% of the range, and if the high minus the highest value between the open and the close - so if the part of the shadow that is above the body - is less than 50% of the absolute value of the body of the bar.

We do this to identify an Up Pin Bar, and we do the opposite to identify a Down Pin Bar, of course. So if there's a downtrend followed by an Up Pin Bar, and the low is the lowest value of the last "n" bars - which are the same bars used to calculate the efficiency ratio of the downward trend - then we have a Hammer pattern. Similarly, if there is a downward trend followed by a Down Pin Bar, we have an Inverse Hammer pattern. Then there are also the MyHangingMan and MyShootingStar patterns. 

This part of the code is necessary to plot what was calculated in the previous lines. Finally, in the last line, we calculate how many times these patterns have occurred in the historical period considered.

Let's open a chart in MultiCharts and see how these patterns were identified.

For example, here we see a Shooting Star. We have an upward trend and then there is a period of indecision, which should then be followed by a downward trend.

Here we find another similar pattern: there's an uptrend and then a small retracement immediately after it.

Now we're looking at the 1440-minute chart of the Eurodollar future. I chose this future because pin bars are generally used in Forex trading. So the first thing I wanted to do was understand if these patterns could be useful from this market. But let's look for some other patterns.

There are more Shooting Stars here. Here it is. Here we have another Hammer. You see, there's a downtrend, then there's the Hammer, and then an uptrend.

Now let's test some entries. For example, let's go and see what happens if we go long when the MyHammer bar closes or, vice versa, if we go short in the presence of a Shooting Star pattern.

Candlestick Patterns Strategy

Let's go back to our Power Language Editor, and this time, we'll see a strategy. This script is very similar to the one with the indicator that I've just shown you. Up Pin Bars and Down Pin Bars are defined in a similar way, and the same goes for the patterns.

What differs is the part related to entries. We go short if the market is flat, so if the market position is equal to zero, and a Hanging Man or Shooting Star pattern occurs. And, conversely, we go long if our market position is equal to zero and a Hammer or Reverse Hammer pattern occurs.

Then, after opening the position, I wrote down some stop-loss and take-profit levels that take into account the size of the range of the bar in which I assume the inversion takes place. So the stop loss for the short entries is equal to the close plus the range of the bar considered, whereas that of the long entries is equal to C (so the close of the current bar) minus the high minus the low.

Here we have the exits and then, after them, I also included a time exit that takes place after three days. Thanks to this exit, in case the trend hasn't taken a clear direction, we'll close the position at the end of the third day. In this case, we can consider the pattern to be no longer effective because too much time has passed.

Alright, let's see how this strategy performs on the Eurodollar future. So we activate the strategy and take a look at the entries and exits in correspondence with our pattern.

Here there's a downtrend, the Hammer, then the strategy went long at the end of the bar, and then it took a profit target depending on the range of the bar in which the pattern took place.

Here we have another similar example of a Hammer. We come from a downtrend, and once again we take the retracement.

Results

Everything looks pretty good on paper as well as on the chart, but if we go and take a look at the Performance Report of this strategy, we see that this pattern occurred only a very few times.

How many, exactly? Well, my List of trades says there were only 11 trades over 11 years. So even if this pattern could be somewhat effective on a daily basis, 11 occurrences in 11 years are definitely too little from a statistical point of view to validate what we have seen.

An alternative could be to test this strategy on a portfolio of instruments. So I decided to test it on a set of currency pairs to see if this approach could be useful and valid from a statistical point of view.

The results of this test are very far from a nice well-performing equity curve. Instead of the 11 trades we had on the Eurodollar, in this case, there are about 200-250 trades, but the shape of the equity is certainly not good. However, before we decide that this strategy is completely useless, I'd like to point out something very important. It's about all the candlestick patterns mentioned in literature as well as the ones we create and find ourselves.

See, what we are doing with these patterns is looking for what we find in a visual way. So I looked for the patterns described in books, in particular the Shooting Star, the Hanging Man, the Reverse Hammer, and the Hammer.

However, we could try and consider these price patterns, these pin bars, not as separate entities but as the construction of two bars. What do I mean by that? If you think about it, this daily bar is nothing more than the result of a market movement that started in this direction, went down to this point, and then went back up.

Just as if there were two 12-hour candlesticks for each 24-hour day. A very large red candlestick followed by a very large green candlestick, both having a body that is much larger than the range.

Final remarks

This way of exploring how patterns are structured could help us better investigate what features may or may not work on the market.

So I invite you to be curious and further investigate and explore things. Don't dwell on what you read in literature. Instead, go deeper and try to find out if there can actually be something true and useful.

This is what we do at Unger Academy, for example. We rely on a very pragmatic and practical analysis following the experience of the 4-time world trading champion Andrea Unger.

If you want to learn more about the world of systematic trading, how to build profitable trading systems and how to manage an entire portfolio of automated strategies, you can find a link in the description of this video. It'll take you to a completely free webinar in which Andrea Unger himself provides a general overview of this world, which is so interesting and just so full of opportunities.

Thank you for watching this whole video! Will see you again in the upcoming technical videos of the Unger Academy.

See you soon! 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.