All About Trading!

Share this post

The RSI-Slope Indicator in TradingView

abouttrading.substack.com

The RSI-Slope Indicator in TradingView

Coding the RSI-Slope Indicator Using Pine Script

Sofien Kaabar, CFA
Sep 5, 2022
Share this post

The RSI-Slope Indicator in TradingView

abouttrading.substack.com

In this article, we will apply a pure approach where we simply calculate the price slope. This should give us an uncorrelated technical indicator that can help us diversify our framework. This slope indicator is a good addition to a systematic trading framework.

Knowledge must be accessible to everyone. This is why, from now on, a purchase of either one of my new books “Contrarian Trading Strategies in Python” or “Trend Following Strategies in Python” comes with free PDF copies of my first three books (Therefore, purchasing one of the new books gets you 4 books in total). The two new books listed above feature a lot of advanced indicators and strategies with a GitHub page. You can use the below link to purchase one of the two books (Please specify which one and make sure to include your e-mail in the note).

Pay Kaabar using PayPal.Me
Go to paypal.me/sofienkaabar and type in the amount. Since it’s PayPal, it’s easy and secure. Don’t have a PayPal…www.paypal.com


The Concept of the Slope

The steepness of two or more points is measured by the slope. A greater slope means a steeper line while a lower slope means a flatter line. We can measure the slope in geometry by using a simple formula. Basically, the slope can be found by measuring the ratio of the vertical change to the horizontal change.

In time series, when we are dealing with the slope of two successive points in time, the slope function shortens to just subtracting the last value by the one preceding it. In case we want the slope of a wider interval, say 5 points in time, we have to use the below formula:

For example, consider the following information on the EURUSD:

  • Current closing price = 1.2300

  • Closing price 5 periods ago = 1.2200

  • Time interval selected = 5 periods

We can find that the slope for this period is therefore the change in the closing prices which is 0.0100 divided by 5, giving us a slope of 0.002.

Source: Lfahlberg — English Wikipedia.

The graph above shows the slope represented by the moving line. Notice how it changes with directional movements on the blue line. Now, we can proceed to applying this concept on a rolling basis.

Check out my weekly market sentiment report to understand the current positioning and to estimate the future direction of several major markets through complex and simple models working side by side. Find out more about the report through this link that covers the analysis between 07/08/2022 and 14/08/2022:

Coalescence Report 7th August — 14th August 2022
THIS IS A FREE SAMPLE GIVEN TO FREE SUBSCRIBERS THIS WEEK. IF YOU WANT TO REGULARLY HAVE THIS REPORT, MAKE SURE TO…coalescence.substack.com


Creating the RSI-Slope Indicator

Beginner and veteran traders are fully aware of the RSI, a famous contrarian indicator that seeks to give reversal signals around extremes. The idea of the RSI-Slope is to apply the formula of the RSI on the calculated slope. This can be done in Pine Script (TradingView) using the following steps:

  • Defining the version and naming the indicator.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Sofien-Kaabar
//@version=5
indicator("RSI-Slope")
  • Defining the default lookback values.

lookback     = input(defval = 21, title = 'Lookback')
lookback_rsi = input(defval = 21, title = 'RSI Lookback')
  • Calculating the slope.

slope      = (close - close[lookback]) / lookback
  • Calculating the RSI of the slope.

indicator  = ta.rsi(slope, lookback_rsi)
  • Plotting.

plot(indicator, color = indicator > 50? color.blue : color.red)
hline(70)
hline(30)
hline(50)
Bitcoin with the RSI-Slope indicator.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Sofien-Kaabar
//@version=5
indicator("RSI-Slope")
lookback     = input(defval = 21, title = 'Lookback')
lookback_rsi = input(defval = 21, title = 'RSI Lookback')
slope      = (close - close[lookback]) / lookback
indicator  = ta.rsi(slope, lookback_rsi)
plot(indicator, color = indicator > 50? color.blue : color.red)
hline(70)
hline(30)
hline(50)
GBPJPY with the RSI-Slope indicator.

Using the RSI-Slope is simple. One of the techniques can be as follows:

  • A long (buy) signal is generated whenever the RSI-Slope is around 30.

  • A short (sell) signal is generated whenever the RSI-Slope is around 70.

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 want to see how to create all sorts of algorithms yourself, feel free to check out Lumiwealth. From algorithmic trading to blockchain and machine learning, they have hands-on detailed courses that I highly recommend.

Learn Algorithmic Trading with Python Lumiwealth
Learn how to create your own trading algorithms for stocks, options, crypto and more from the experts at Lumiwealth. Click to learn more


Summary

To sum 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 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.

Share this post

The RSI-Slope Indicator in TradingView

abouttrading.substack.com
Comments
TopNewCommunity

No posts

Ready for more?

© 2023 Sofien Kaabar
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing