Volatility Momentum in Python

Coding and Trading a Volatility-Adjusted RSI in Python

Sofien Kaabar, CFA
8 min readOct 22, 2022


Structured indicators are the result of fusing two or more together to form a weighted or adjusted indicator that takes into account more variables. For example, we know that there is a Stochastic-RSI indicator which combines the two formulas together in an attempt to improve the signals, this article discusses the creation of an RSI-ATR indicator which adjusts the RSI for the average true range, a measure of volatility.

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.

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.



Sofien Kaabar, CFA

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