The GRI Range Index Trading Strategy.
Creating & Trading the Gopalakrishnan Range Index in Python.
Some indicators are specifically used for detecting regimes and volatility as opposed to directional indicators. This article discusses the Gopalakrishnan Range Index which helps us understand the current state.
I have just published a new book after the success of my previous one “New Technical Indicators in Python”. It features a more complete description and addition of structured trading strategies with a GitHub page dedicated to the continuously updated code. If you feel that this interests you, feel free to visit the below link, or if you prefer to buy the PDF version, you could contact me on LinkedIn.
Creating the GRI Index
Also called the GAPO index, the GRI calculates the relative strength between the highs and lows divided by their lookback period.
If in a certain lookback period, the difference between the highest highs and the lowest lows is increasing, then the indicator will rise. If the the index is showing a flat reading, it means that the market has failed to make a higher high and a lower low, therefore, the reading remains stable.
Any time a new high or a new low is made, the indicator’s value will increase to adjust to this, which is why it is a trending indicator.
# The function to add a number of columns inside an array def adder(Data, times): for i in range(1, times + 1): new_col = np.zeros((len(Data), 1), dtype = float) Data = np.append(Data, new_col, axis = 1) return Data # The function to delete a number of columns starting from an index def deleter(Data, index, times): for i in range(1, times + 1): Data = np.delete(Data, index, axis = 1) return Data # The function to delete a number of rows from the beginning def jump(Data, jump): Data = Data[jump:, ] return Data # Example of adding 3 empty columns to an array my_ohlc_array = adder(my_ohlc_array, 3) # Example of deleting the 2 columns after the column indexed at 3 my_ohlc_array = deleter(my_ohlc_array, 3, 2) # Example of deleting the first 20 rows my_ohlc_array = jump(my_ohlc_array, 20) # Remember, OHLC is an abbreviation of Open, High, Low, and Close and it refers to the standard historical data file def gri_index(Data, lookback, high, low, where): Data = adder(Data, 1) for i in range(len(Data)): try: Data[i, where] = abs(np.log(max(Data[i - lookback + 1:i + 1, high]) - min(Data[i - lookback + 1:i + 1, low])) / np.log(lookback)) except ValueError: pass return Data
One limitation of the GRI is that it does not tell you the direction of the trend. You have to detect it yourself.
lookback = 14 my_data = gri_index(my_data, lookback, 1, 2, 4)
Creating a Strategy on the GRI
The GRI index can be used in many trend-following strategies. Due to its nature of confirming new highs and new lows, we can list a few strategies below:
The market is trending if the GRI is going up, therefore, we can set thresholds to surpass so that we understand when we can call the market a trending one.
If the GRI is flat, then we can use the highest point in the market as a resistance level and the lowest point in the market as a support level.
We can use the GRI with the MACD to confirm the trend. A suggested strategy is that whenever we see a MACD cross and a rising GRI, then we can have a better conviction.
If you are also interested by more technical indicators and using Python to create strategies, then my best-selling book on Technical Indicators may interest you:
Remember to always do your back-tests. You should always believe that other people are wrong. My indicators and style of trading may work for me but maybe not for you.
I am a firm believer of not spoon-feeding. I have learnt by doing and not by copying. You should get the idea, the function, the intuition, the conditions of the strategy, and then elaborate (an even better) one yourself so that you back-test and improve it before deciding to take it live or to eliminate it. My choice of not providing specific Back-testing results should lead the reader to explore more herself the strategy and work on it more.
To sum up, are the strategies I provide realistic? Yes, but only by optimizing the environment (robust algorithm, low costs, honest broker, proper risk management, and order management). Are the strategies provided only for the sole use of trading? No, it is to stimulate brainstorming and getting more trading ideas as we are all sick of hearing about an oversold RSI as a reason to go short or a resistance being surpassed as a reason to go long. I am trying to introduce a new field called Objective Technical Analysis where we use hard data to judge our techniques rather than rely on outdated classical methods.