Super indicators are not frequent but they add immense values to our trading. Among these super indicators is the premier RSI, a complex version that resembles the RSI but enhances it and makes it more reactive. This article discusses all you need to know about the premier RSI.

I have released a new book after the success of my previous one “*Trend Following Strategies in Python*”. It features advanced contrarian indicators and strategies with a **GitHub **page dedicated to the continuously updated code. If you feel that this interests you, feel free to visit the below Amazon link (which contains a sample), or if you prefer to buy the PDF version, you could check the link at the end of the article.

**Contrarian Trading Strategies in Python***Amazon.com: Contrarian Trading Strategies in Python: 9798434008075: Kaabar, Sofien: Books*www.amazon.com

### 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.

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

```
def delete_row(data, number):
data = data[number:, ]
return data
```

```
def ma(data, lookback, close, position):
data = add_column(data, 1)
for i in range(len(data)):
try:
data[i, position] = (data[i - lookback + 1:i + 1, close].mean())
except IndexError:
pass
data = delete_row(data, lookback)
return data
```

```
def smoothed_ma(data, alpha, lookback, close, position):
lookback = (2 * lookback) - 1
alpha = alpha / (lookback + 1.0)
beta = 1 - alpha
data = ma(data, lookback, close, position)
```

` data[lookback + 1, position] = (data[lookback + 1, close] * alpha) + (data[lookback, position] * beta)`

```
for i in range(lookback + 2, len(data)):
try:
data[i, position] = (data[i, close] * alpha) + (data[i - 1, position] * beta)
except IndexError:
pass
return data
```

```
def rsi(data, lookback, close, position):
data = add_column(data, 5)
for i in range(len(data)):
data[i, position] = data[i, close] - data[i - 1, close]
for i in range(len(data)):
if data[i, position] > 0:
data[i, position + 1] = data[i, position]
elif data[i, position] < 0:
data[i, position + 2] = abs(data[i, position])
data = smoothed_ma(data, 2, lookback, position + 1, position + 3)
data = smoothed_ma(data, 2, lookback, position + 2, position + 4)
```

```
data[:, position + 5] = data[:, position + 3] / data[:, position + 4]
data[:, position + 6] = (100 - (100 / (1 + data[:, position + 5])))
```

```
data = delete_column(data, position, 6)
data = delete_row(data, lookback)
```

` return data`

Make sure to focus on the concepts and not the code. You can find the codes of most of my strategies in my books. The most important thing is to comprehend the techniques and strategies.

If you are also interested by trend following strategies and indicators, then my previous book might also interest you:

**Trend Following Strategies in Python: How to Use Indicators to Follow the Trend.***Amazon.com: Trend Following Strategies in Python: How to Use Indicators to Follow the Trend.: 9798756939620: Kaabar…*www.amazon.com

### Creating the Premier RSI in Python

Let’s now create this highly complex but extremely interesting indicator. Originally created as a variation of the stochastic oscillator by Lee Leibfarth in 2008, the premier RSI is another attempt at a bounded indicator that is considered to be more reactive and leading. Therefore, it is an enhanced version which has its own unique trading conditions that I will present later. First, we need to understand how to calculate it. Follow these steps:

Calculate an 8-period RSI. You have already seen how to do this.

Calculate a transformed RSI using the following formula:

Calculate a 5-period exponential moving average on the transformed RSI.

Calculate another 5-period exponential moving average on the results from the previous step.

Calculate the exponents of the double smoothed values from the previous step.

Finally, apply the below normalization function on the results from the last step to obtain the PRSI:

Now, you have a PRSI calculated from an 8-period RSI smoothed with a 5-period double exponential moving average. The next step is to visualize the indicator and discuss the trading conditions.

The PRSI is used as follows:

**A long (buy) signal is generated whenever the PRSI drops below 0.20 after having been above it.****A short (sell) signal is generated whenever the PRSI rises above -0.20 after having been below it.**

Interestingly, the same conditions can be generated by using 0.90 and -0.90. However, in this article, I will stick to the -0.20/0.20 rules.

Before coding the PSO, make sure you define the function of the exponential moving average:

```
def ema(data, alpha, lookback, close, position):
alpha = alpha / (lookback + 1.0)
beta = 1 - alpha
data = ma(data, lookback, close, position)
```

` data[lookback + 1, position] = (data[lookback + 1, close] * alpha) + (data[lookback, position] * beta)`

```
for i in range(lookback + 2, len(data)):
try:
data[i, position] = (data[i, close] * alpha) + (data[i - 1, position] * beta)
except IndexError:
pass
return data
```

Let’s check the signals generated on the PRSI. The below shows the USDCHF with triggers coming from the conditions discussed previously.

```
def prsi(data, lookback_rsi, lookback_smoothing, high, low, close, position):
data = add_column(data, 10)
data = rsi(data, lookback_rsi, close, position)
data[:, position + 1] = 0.10 * (data[:, position] - 50)
lookback_smoothing = np.sqrt(lookback_smoothing)
lookback_smoothing = int(round(lookback_smoothing, 0))
data = ema(data, 2, lookback_smoothing, position + 1, position + 2)
data = ema(data, 2, lookback_smoothing, position + 2, position + 3)
data[:, position + 4] = np.exp(data[:, position + 3])
data[:, position + 5] = (data[:, position + 4] - 1) / (data[:, position + 4] + 1)
data = delete_column(data, position, 5)
return data
```

The below shows the GBPUSD with triggers coming from the conditions discussed previously.

In a future article, I will compare the original RSI with the PRSI.

### Summary

To summarize up, what I am trying to do is to simply contribute to the world of objective technical analysis which is promoting more transparent techniques and strategies that need to be back-tested before being implemented. This way, technical analysis will get rid of the bad reputation of being a subjective and scientifically unfounded.

I recommend you always follow the the below steps whenever you come across a trading technique or strategy:

Have a critical mindset and get rid of any emotions.

Back-test it using real life simulation and conditions.

If you find potential, try optimizing it and running a forward test.

Always include transaction costs and any slippage simulation in your tests.

Always include risk management and position sizing in your tests.

Finally, even after making sure of the above, stay careful and monitor the strategy because market dynamics may shift and make the strategy unprofitable.

For the PDF alternative, the price of the book is **9.99 EUR**. Please include your email in the note before paying so that you receive it on the right address. Also, once you receive it, make sure to download it through google drive.

**Pay Kaabar using PayPal.Me***If you accept cookies, we’ll use them to improve and customize your experience and enable our partners to show you…*www.paypal.com