Inside bars can be a valuable predictor of trend continuation. Here’s how you can program an inside bar, and use it to improve your trend following strategy!
You can download the strategy below from the Free Strategies section.
Trend following is a reliable income generator for many retail traders.
Jumping aboard a trend after a pullback or consolidation is a great way to improve your win rate and entry price.
Here I’ll illustrate how you can use inside bars to predict trend continuation for the M30 GBPJPY.
What is an Inside Bar?
An inside bar is one whose price range (candle wicks included) is completely within the price range of its preceding candle.
Algorithmically speaking, the inside bar’s high must be lower than the previous high, and the inside bar’s low must be higher than the previous low.
Market volatility is often cyclical in nature. Periods of intense activity are usually followed by periods of relative calm.
These inside bars indicate a brief period of calmness.
Market participants could be taking profits after riding the initial wave of a trend, or they could be awaiting a major news release.
During such periods of consolidation, any fundamental impetus (such as a positive economic report) can create a strong breakout.
Trades who were previously waiting on the sidelines quickly jump into the market, amplifying and sustaining the emerging trend. The longer the prior consolidation, the stronger the breakout tends to be.
Using Inside Bars for Trend Following
Inside bars can be used to predict trend reversals and continuations.
I’ll focus on trend continuations in this case.
This is the scenario I’ll try to capture when programming the inside bar strategy:
- A brief trend is followed by consolidation
- An inside bar occurs, indicating low volatility
- The market breaks out of the consolidation range, continuing the trend
Pattern recognition is often a weak point of algorithmic trading. Even patterns that are obvious to the human eye are difficult to convert into a set of black-and-white programming rules.
Let’s give it a shot.
Programming Inside Bars
To avoid going insane, I’m going to start with a very loose set of trading rules. Here’s the rules for detecting an uptrend continuation:
- An upwards bar occurs, meaning prices close higher.
- This is followed by an inside bar.
- Another upwards bar occurs.
Here’s how it looks like on a chart:
And now some quick programming with AlgoWizard:
The number in square brackets indicates the bar shift.  means the most recently completed bar, while  refers to the bar before that, and so on.
The rules for detecting downtrends are the opposite:
- A downwards bar occurs, meaning prices close lower.
- This is followed by an inside bar.
- Another downwards bar occurs.
And in AlgoWizard:
Simple programming rules like these help minimize the risk of curve fitting.
Programming Entry Filters
While simple entry conditions are generally good, I need to minimize the chance of catching false breakouts.
I’ll add two entry filters to help with this – A long-term trend filter, and a stop order filter.
1. Trend Filter
With this filter, I will only trade in the direction of the long-term trend.
Long trades will only be taken when prices close above the 100-period exponential moving average (EMA).
Conversely, shorts will require the close to be below the 100-period EMA.
2. Stop Order Filter
When the above entry conditions are met, a buy stop will be placed at the previous high. This means I’ll only enter the market after seeing some evidence of trend continuation.
For shorts, the sell stop will be placed at the previous low.
Finally, for risk management, I’ll throw in a 120-pip trailing stop and exit all trades on Friday.
With all the entry conditions above, a long entry now looks like this:
And a short entry:
Backtesting the Inside Bar Trend Strategy
As usual, I run a 10-year backtest to verify that the strategy has some long-term edge.
The GBPJPY is known to trend pretty well. Are the results above purely due to the choice of market?
To find out, I removed the inside bar conditions. The strategy now places buy/sell stops when prices close above/below the 100-period EMA, respectively.
I wouldn’t touch that with a ten-foot pole.
I’ve found that adding some sort of pullback/consolidation filter, like the inside bar conditions in this case, usually improve your trend following strategy.
Inside bars represent volatility contraction and commonly appear when a trend is consolidating.
A breakout of the consolidation range gives you an opportunity to jump onboard the trend.
The entry conditions above should be used as a starting point. You can improve your win rate by being more selective with your inside bars.
Ideally, you want to see the classic ‘Harami Cross’ pattern:
- A very small range relative to the previous bar
- A thin real body, indicating indecision in the market
If you want the backtest the inside bar strategy above, you can download it from the Free Strategies section.