Bollinger Bands are great at detecting overbought and oversold conditions. Let’s use them to develop a countertrend strategy, and then refine our entries using limit entries and candlestick patterns.
The complete strategy can be downloaded in the Free Strategies section.
A Bollinger Bands Primer
Bollinger Bands are one of the marvels of technical trading. They consist of a simple moving average surrounded by a pair of upper and lower bands. These bands are placed at a certain standard deviation multiple above and below the moving average.
Bollinger Bands are typically defined by two parameters – the moving average lookback period, and the standard deviation multiple. By default, a 20-period lookback and a standard deviation multiple of 2 are used.
If prices followed a normal distribution, they would fall within the bands 95% of the time. In reality, however, the presence of the occasional price surge brings the percentage closer to the 85-90% range.
Since the upper and lower bands are based on standard deviation, the Bollinger Bands provide a graphical representation of market volatility. High volatility causes the bands to expand, while low volatility causes them to contract, or ‘squeeze’.
Like most indicators, Bollinger Bands can be used in both a trend and countertrend manner. I previously discussed the development of a Bollinger Band trend following strategy that performed pretty well on the GBPJPY.
Let’s go countertrend this time.
Bollinger Bands and Countertrend Trading
Since prices remain within the bands most of the time, the market is considered overbought when prices close above the upper band, and oversold when prices close below the lower band.
In countertrend trading, we are speculating that prices will return to the mean after a temporary overextension. Overbought conditions present good opportunities to short the market, while oversold conditions are great for longs.
We want to react quickly to capture the overbought/oversold conditions when they occur. A short lookback period is required here. The default lookback of 20 should do fine.
The standard deviation multiple is an important parameter has a large influence on the number of trades. Ideally, we want to filter out as many false signals as possible, yet obtain a significant number of trades. Bollinger Bands with standard deviation multiples of 2, 2.5, and 3 are plotted below.
When a multiple of 3 is used, it seems prices rarely penetrate the bands even when the market is trending. Let’s stick with the default multiple of 2 for now. It can be optimized later if needed.
What Market and Timeframe?
An important consideration for any strategy is the choice of market and timeframe.
Although the goal is to develop a robust strategy that performs well over different markets, it makes no sense to develop a countertrend strategy for a traditionally trending market. We need a mostly range-bound market.
When selecting a market, it pays to think about the fundamental characteristics of the currency. We want currencies that are highly correlated, such that they will usually move in tandem with each other.
AUDNZD immediately comes to mind. The Australian and New Zealand dollar hail from the same geographical area and are both risk-on, commodity-based currencies. Moreover, both countries have China as their biggest trading partner. Any change in China’s economic fortunes will affect both currencies significantly.
We’ll give AUDNZD a go here.
How about timeframe? Since we want to fade the market, we are betting that the price extension was a result of random market noise. Since lower timeframes generally exhibit higher levels of noise, let’s try the 15-minute timeframe.
If you suspect the price movement is caused by fundamental factors such as economic reports or central bank decisions, it’s probably best not to adopt a countertrend strategy for the time being.
Trading Strategy Logic
For starters, we’ll try the following simple rules:
Buy when prices close below the lower Bollinger Band
Sell when prices close above the upper Bollinger Band
Market orders will be used for entry. How about trade management?
There’s a pretty good chance that prices will soon return to the mean after being overbought/oversold, so let’s use a larger stop loss distance to give the trade more breathing space.
Realistically, we can only expect prices to return to the ‘average’ value. We won’t be capturing a large number of pips per trade like trend following strategies do.
So let’s have a profit target that is half that of our stop loss. The high win rate should make us profitable.
We’ll just plug in a 60-pip profit target and a 120-pip stop loss.
Results of Our Bollinger Bands Starter Strategy
The strategy was programmed with AlgoWizard. If you’re looking for a visual strategy builder, and don’t fancy learning programming, check out my step-by-step guide on creating a strategy in AlgoWizard.
The backtest used 1-minute AUDNZD data over the past 10 years.
Wow! That didn’t go according to plan. We have a healthy sample of 811 trades, but only 65% were winning. I expect a higher win rate for countertrend strategies.
I suspect too many false signals were captured. In other words, after entering the trade, prices continued to diverge from the mean. To improve the strategy, we’ll try to:
- Get a better entry price using limit orders
- Add a candlestick pattern filter to reject false signals
Entering With Limit Orders
A limit order allows you to enter the market at a specific price or better. For longs, you can place a buy limit below the market price. Your order will be filled if prices fall. For shorts, the sell limit would be above the market price.
Apart from giving you a more favourable price, entering on a limit order increases the likelihood of catching a price rebound. Think of stretching a rubber band. The further you stretch it, the more forcefully it rebounds. Of course, sometimes the rubber band breaks, in which case the prices start trending.
What price should we use for the limit orders? A simple option would be to use the previous candle’s low for the buy limit, and the previous candle’s high for the sell limit.
You also need to specify a validity period for limit orders. If the overbought/oversold condition is a result of random noise, the rebound towards the mean should occur shortly. A 3-bar validity period seems appropriate.
The entry actions in AlgoWizard were modified as follows:
Now let’s redo the backtest.
I’m surprised at how much results have improved.
I’m also surprised that both strategies have a similar number of trades (811 vs. 810). It is unlikely that practically every limit order was triggered within 3 bars. Surely the two strategies used different entry signals?
To be sure, I combined both strategies into a portfolio and measured the correlation of their daily profits/losses. The correlation coefficient was fairly low at 0.37, implying that different entry signals were used (fortunately).
The average size of winners and losers are also similar, since the stop loss and take profit levels were unchanged.
So it seems the improvement in performance is purely down to the higher win rate of 69%.
Not bad, but we’re not done yet. 69% is still too low for my liking. Fortunately, with 810 trades, we can afford to be picky and add some entry filters.
Adding a Candlestick Pattern Entry Filter
Candlestick patterns help traders discern the dynamics between buyers and sellers.
Since our countertrend strategy bets on prices reversing back towards the mean, let’s consider the four popular reversal candlestick patterns below.
A Doji is a candlestick with a narrow body, accompanied by long shadows at both ends. After reaching an overbought/oversold condition, this indecision in the market could signal an upcoming reversal.
Dojis can be either bullish or bearish signals, depending on the preceding price action.
2. Hammer/Shooting Star
A hammer is a bullish reversal candlestick, consisting of a small body and a long lower shadow. Prices initially head lower, but buyers eventually overcome sellers, pushing prices back up towards the open.
The shooting star is the opposite of the hammer, and signals a possible bearish reversal.
3. Bullish/Bearish Engulfing
A bullish engulfing is a two-candlestick pattern. A small bearish candle is followed by a large bullish candle, whose body completely engulfs the body of the first candle. This could signal a powerful bullish reversal.
Bearish engulfings are the opposite.
4. Piercing Pattern/Dark Cloud Cover
These could be considered less potent versions of the engulfing candlestick patterns.
In the Piercing Pattern, a bearish candle is followed by bullish candle that gaps lower at the open. This bullish candle eventually closes above the midpoint of the bearish candle, signalling a possible bullish reversal.
The Dark Cloud Cover is the opposite.
In general, the more candlesticks a pattern contains, the more reliable it is. For example, bullish engulfings are generally more reliable than hammers.
Regardless of the candlestick pattern you use, it’s also a good idea to examine the preceding candles. Reversal candlestick patterns that occur after prolonged uptrends/downtrends are more reliable.
Programming the Candlestick Patterns
To get more trades, our entry filter will pass if any one of the above four candlestick patterns is present. The ‘or‘ operator will thus be used to link the candlestick pattern conditions.
The candlestick patterns will be added to the upper/lower Bollinger Band penetration conditions. This means entry signals will only be generated when prices penetrate the upper/lower bands and one of the above candlestick patterns is present.
Fortunately, these candlestick patterns are already pre-programmed in AlgoWizard. You won’t have to manually define a pattern by quantifying the OHLC relationships between the candles.
The AlgoWizard entry conditions were updated as follows:
With limit entry orders and candlestick filters, our backtest results look much better.
By focusing on high probability reversal setups, the candlestick pattern filter rejected half of the original 810 trades.
The win rate is up to 72%, and the resulting 1.26 profit factor is far more palatable.
A cursory glance at the Trade analysis tab in AlgoWizard reveals that the strategy was profitable on all weekdays except Monday.
Trading volumes are typically lower on Mondays. Countertrend strategies tend to perform better in quiet markets, so this result is a little surprising.
It’s easy to add a day-of-the-week entry filter, but that’d be like putting one foot into the curve fitting pond, so I’ll keep the strategy as it is.
If you wish to add it, you just need to add the entry condition below:
Let’s Talk Backtest Precision
When backtesting, there is always a trade-off between precision and time requirements. Are the preceding backtests precise enough?
To save time, all the above results were obtained using a simplified backtest model. In this model,
- Strategy logic is only evaluated at the opening of each bar
- Only the OHLC prices of the completed bars are considered
If your strategy often executes trading actions in the middle of a bar, this simplified backtest model could produce inaccurate results.
Our strategy’s 60-pip profit target and 120-pip stop loss are always in the market, so they could be triggered anytime. But the average bar range of the M15 AUDNZD is usually below 20 pips, so the inaccuracies should not be too severe.
Regardless, let’s go ahead and verify our backtest results with tick data.
To find out whether you need a tick backtest, and where to get quality tick data, head over to my article on tick backtesting.
Performing a Tick Backtest
I used Tickstory tick data and reran the final backtest over the past 10 years.
You should get 0 mismatched charts errors and a 99.90% modelling quality.
Pertinent metrics such as the total trades and expectancy are very similar (~3% discrepancy). Most importantly, the equity curves look similar.
In addition, I can be more confident that the backtests are reliable since both the AlgoWizard and MT4 backtest engine produced similar results.
Nonetheless, it is unlikely that any backtest engine can perfectly model the filling of limit orders. In live trading, liquidity issues may mean that only part of your order will be executed at the limit price. If you are serious about using limit orders, it’s recommended to do some forward testing under real market conditions.
So a simple Bollinger Bands strategy augmented with candlestick patterns can indeed work!
Some market research will help you select an appropriate market for the above strategy. You probably should avoid volatile, trendy markets!
Unfortunately, the strategy doesn’t trade much; there were only 3 trades/month over the past 10 years. To get more trades, you can add in more candlestick patterns, including those containing 3 candles.
If you want to play around with the complete strategy, you know where to find it.