Tradingview: Inside Bar Momentum Strategy

The strategy contained in this post comes courtesy of, an excellent resource for all thing forex related. If you are new to trading, the site is definitely worth checking out. Even if you don’t intend to trade Forex!

We are going to take a look at a strategy which has been tested and reviewed on the site since 2017. The strategy in focus is an Inside Bar Momentum strategy which according to the latest reports on the site has had excellent live performance throughout 2018 to date. As such, that makes it an interesting strategy to replicate and backtest.

What is an Inside Bar?

An inside bar is the name of a candle which can fully fit inside the candle before it. The means that the previous candle’s high is higher than the “Inside Bar” candle high. Additionally, the previous bar’s low is lower than the “Inside Bar” candle low.

Inside Bars can be used as technical analysis signal for price action strategies. It is thought that inside bars could indicate a pause or breather in the market before a bigger move happens. If you are familiar with it, this is a similar concept to the Bollinger squeeze. I.e. the calm before the storm!

This particular strategy theorizes that the “Inside Bar” is signalling a pause before momentum continues in the same direction. I should note that it not explicitly stated in the authors’ post. Howeveer, the ruleset certainly appears to confirm this interpretation.

Before we get into the rules though, let’s solidify our understanding of the inside bar with a visual example. This will make it very obvious what we shall be looking for.

Inside Bar Examples

Inside Bar Momentum Strategy

For a complete overview of the ruleset, you should check out the strategy article on baby pips. It is only fair to the original author. However, for those who hate to click on links, a summary of the key points is provided below.

Strategy Source:

The strategy focuses on “setups” rather than signals. This means that we do not enter a trade as soon as we receive a signal. Instead, the signal will highlight a potential setup which may or may not come to fruition. Once we identify the setup, we send a stoporder to attempt to enter an ideal level once the setup is confirmed.

  • Long Setup: An Inside bar is detected and the candle before the inside bar is green
  • Short Setup: An Inside bar is detected and the candle before the inside bar is red

As mentioned above, once we have identified the setup, we enter a stoporder at a given distance (percentage) away from the high or low of the bar before the inside bar. It will be the highfor long setups and the lowfor short setups.

  • Exit: Simple take profit and stop loss measure from the high or low of the bar before the inside bar. (Not the entry price!)

Special note: If a new Inside bar is detected while we are in a position, we with close it with a marketorder. If a new inside bar is detected but we have not triggered out entry level, then we start again. I.e cancel our entry order and create a new one.

The Code


The code attempts to faithfully follow the ruleset provided on babypips with a few additional extras:

  • Variable entry, stop and profit levels
  • Backtest date ranges
  • Position Sizing

Of the three additional extras, it is the position sizing algorithm that could do with a few extra words. Position sizing is not mentioned in the author’s original post. However, it is clear that the strategy has a fixed risk. Only only chances of exiting at a loss are through our stop loss or through the market order (which is triggered before we hit the stop). Therefore, this strategy is an ideal candidate to benefit from some larger position sizing.

In Forex markets it is common for traders to size their position so that if their stoploss is hit, it will result in losing a fixed x% of their overall account. Given that stop losses are not a zero, this results in a much larger quantity than just dividing a percentage of the account by the price. It also means that the position size will change depending on how far your stop loss is from your entry price. If it is far away, your position size will be smaller. Conversely, if it is closer, your position size can be much larger whilst only risking the same amount.

We calculate our position size with the following line:

long_qty = floor((strategy.equity * Risk) / (Long_Stop_Buy_Level - Long_Stop_Loss_Level))

It is worth noting that since we calculate our qtymanually, Order Sizein the strategy properties tab will have no impact on the position size.

Additional Note: The code in this post only works effectively, if your account currency is the same as the counter currency.  I.e If you are trading GBPUSD and your account currency is USD. If it is not the base currency, Traders must perform an FX conversion first. The code in this post does not cover that. However, the account currency in this strategy is set to defaultwhich will automatically be the counter currency.

On the Charts

When loading up the strategy for the first time, you will see something that looks like this:

Inside Bar Momentum Strategy On The Charts

The only eye-candy on display is a simple marker to highlight when inside bars are detected.


Since this strategy was posted on an FX website, it is only fitting to take a look at some forex pairs first. Following this, we will take a quick look at how it handles some other markets.

Important Note: Some of the results below appear a little too good to be true. In general, if it appears that way, it usually is! So take these results with a healthy dose of caution. There could be something mechanically funky going on like we discovered in: Tradingview: Trailing Stop Mechanics (Beware Version 3).

All backtests below were performed WITHOUT commission (important point because commissions can cause death by 1000 paper cuts) from Jan 2018 to July 2018.

Forex – GBPUSD

Indices – S&P 500

Commodities – Gold

Crypto – BTCUSD

Find This Post Useful?

If this post saved you time and effort, please consider support the site! There are many ways to support us and some won’t even cost you a penny.