Combining the SuperTrend With the RSI

How to Create a Trend-Following Strategy in Python

Sofien Kaabar, CFA
9 min readNov 28, 2022


Trend following strategies rely on confirmation techniques to detect as early as possible a new trend. This article discusses a strategy on the RSI and the SuperTrend.

Medium is a hub to interesting reads. I read a lot of articles before I decided to start writing. Consider joining Medium using my referral link (at NO additional cost to you).

The Relative Strength Index

First introduced by J. Welles Wilder Jr., the RSI is one of the most popular and versatile technical indicators. Mainly used as a contrarian indicator where extreme values signal a reaction that can be exploited. Typically, we use the following steps to calculate the default RSI:

  • Calculate the change in the closing prices from the previous ones.
  • Separate the positive net changes from the negative net changes.
  • Calculate a smoothed moving average on the positive net changes and on the absolute values of the negative net changes.
  • Divide the smoothed positive changes by the smoothed negative changes. We will refer to this calculation as the Relative Strength — RS.
  • Apply the normalization formula shown below for every time step to get the RSI.
GBPUSD in the first panel with the 13-period RSI in the second panel.

The above chart shows the hourly values of the GBPUSD in black with the 13-period RSI. We can generally note that the RSI tends to bounce close to 25 while it tends to pause around 75. To code the RSI in Python, we need an OHLC array composed of four columns that cover open, high, low, and close prices.

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 =…



Sofien Kaabar, CFA

Top writer in Finance, Investing, Business | Trader & Author

Recommended from Medium


See more recommendations