Harnessing the Hull RSI: A Comprehensive Guide to Coding
Written on
Chapter 1: Introduction to the Hull RSI
In this guide, we delve into the Hull Relative Strength Index (RSI) and its coding in Python. The Hull moving average (HMA) is known for its reduced lag, making it a valuable tool in refining the signals generated by the traditional RSI, which incorporates a smoothed moving average in its calculations. The primary objective here is straightforward: to substitute one element within the RSI formula for improved results.
I have recently published a new book following the success of my earlier work, "Trend Following Strategies in Python." This new book covers advanced contrarian indicators and strategies, along with a dedicated GitHub repository for continuously updated code. If you're interested, you can purchase the PDF version for 9.99 EUR via PayPal. Please remember to include your email in the payment note to ensure it reaches you. After you receive it, make sure to download it from Google Drive.
Section 1.1: Understanding the Relative Strength Index
The Relative Strength Index, created by J. Welles Wilder Jr., is a highly regarded technical indicator widely used in trading. Primarily, it serves as a contrarian indicator, where extreme values indicate potential market reversals. The standard steps to calculate the RSI include:
- Assessing changes in closing prices from previous values.
- Distinguishing positive changes from negative ones.
- Applying a smoothed moving average to both positive and negative changes.
- Dividing the smoothed positive changes by the smoothed negative changes to derive Relative Strength (RS).
- Finally, applying the normalization formula to obtain the RSI for each time point.
The chart below illustrates the GBPUSD hourly values along with the 13-period RSI.
Section 1.2: Coding the RSI in Python
To implement the RSI in Python, we require an OHLC (Open, High, Low, Close) array. Below is a snippet that demonstrates how to manage the data:
import numpy as np
def add_column(data, times):
for i in range(1, times + 1):
new = np.zeros((len(data), 1), dtype=float)
data = np.append(data, new, axis=1)
return data
def delete_column(data, index, times):
for i in range(1, times + 1):
data = np.delete(data, index, axis=1)return data
Chapter 2: The Hull Moving Average
The Hull Moving Average is designed to confirm trends and is a widely recognized indicator due to its simplicity and proven effectiveness. It helps identify support and resistance levels, as well as entry and exit points in trading.
The core of the Hull moving average relies on the linear-weighted moving average (LWMA), which assigns greater weight to more recent data points, thereby reducing lag compared to traditional moving averages. The formula for calculating the Hull moving average involves several steps:
- Select a lookback period and compute the weighted moving average of the closing price.
- Use half of the lookback period to calculate another weighted moving average.
- Multiply the second moving average by two and subtract the first moving average.
- Finally, calculate the square root of the initial lookback period to determine the next moving average.
The following code snippet illustrates how to compute the Hull moving average:
def hull_moving_average(Data, what, lookback, where):
Data = lwma(Data, lookback, what)
second_lookback = round((lookback / 2), 1)
Data = lwma(Data, second_lookback, what)
Data = adder(Data, 1)
Data[:, where + 2] = ((2 * Data[:, where + 1]) - Data[:, where])
third_lookback = round(np.sqrt(lookback), 1)
Data = lwma(Data, third_lookback, where + 2)
return Data
The Hull RSI merges the advantages of both the Hull moving average and the traditional RSI, leading to a more responsive and volatile indicator. This can enhance your trading strategies significantly.
In conclusion, my aim is to contribute to the sphere of objective technical analysis by promoting transparent techniques and strategies that can be thoroughly back-tested. By following the outlined guidelines, traders can improve their understanding and application of these concepts.
Always approach trading with a critical mindset, thoroughly back-test strategies, and stay vigilant as market dynamics can shift.