Discover more from All About Trading!
Back-testing the Internal Bar Strength Trading Strategy
Coding and Back-testing the IBS Strategy in TradingView
Algorithmic trading strategies can also be simple. This article presents one and back-tests it in TradingView.
The Fibonacci Trading Book is finally out! Filled with Fibonacci-based trading methods (tools, indicators, patterns, and strategies), this book will guide you through improving your trading and analysis by incorporating an important technical analysis approach that is Fibonacci [PDF Version available, see end of article).
Introduction to the IBS
Technical indicators are tools used in technical analysis to analyze and predict future price movements in financial markets, such as stocks, commodities, or currencies. These indicators are based on mathematical calculations derived from historical price and volume data. Traders and analysts use these indicators to gain insights into market trends, identify potential entry or exit points, and make informed trading decisions.
The internal bar strength (IBS, very unfortunate name) is a very simple formula used in some algorithmic trading strategies. It follows this calculation:
On a chart, the IBS looks like a stationary indicator hovering between 0 and 1:
Obviously, the indicator is positively correlated to the price action (as can be understood from the formula and the chart). The aim now is to derive trading rules (entries and exits) to trade the S&P 500 index.
Coding and Back-testing the Strategy
The rules for the IBS strategy (long-only) are as follows:
A bullish signal is generated whenever the IBS dips below 0.20.
The exit rule after the bullish signal is when the IBS surpasses 0.90.
The following shows the equity curve on daily bars (no transaction costs have been included as they are variable):
The average trade duration is around 9 days, making it a swing trading strategies. The hit ratio is acceptable given a risk-reward ratio less than 2.00. The profit factor shows good profitability by being well above 1.0. The number of trades may be optimized to reduce costs (when incorporated). However, the number of trades may suggest that this strategy will not outperform a simple passive strategy (buy-and-hold). But, optimization parameters may help with that.
The code used to generate the back-test is as follows:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © Sofien-Kaabar //@version=5 strategy("My strategy", overlay=true, margin_long=100, margin_short=100) ibs = (close - low) / (high - low) buy = input(defval = 0.2, title = 'Buying Level') sell = input(defval = 0.8, title = 'Selling Target') longCondition = ibs < buy and ibs > buy if (longCondition) strategy.entry("My Long Entry Id", strategy.long) strategy.close('My Long Entry Id', when = ibs >= sell)
The PDF link for the Fibonacci Trading Book is the following (make sure to include your e-mail address in the notes part):
If you want to see how to create all sorts of algorithms yourself, feel free to check out Lumiwealth. From algorithmic trading to blockchain and machine learning, they have hands-on detailed courses that I highly recommend.
Learn Algorithmic Trading with Python Lumiwealth
Learn how to create your own trading algorithms for stocks, options, crypto and more from the experts at Lumiwealth. Click to learn more