Strategy Creation

What is RSI and How to Use It in Tuned Script

Mr. Plippy

What Is the Relative Strength Index (RSI)?

The relative strength index (RSI) is a momentum indicator used in technical analysis that measures the magnitude of recent price changes to evaluate overbought or oversold conditions in the price of a stock or other asset. The RSI is displayed as an oscillator (a line graph that moves between two extremes) and can have a reading of 0 to 100.

RSI_1.PNG

Key points about the RSI

  1. The RSI is a very popular momentum oscillator
  2. The RSI provides bullish and bearish momentum signals
  3. Usually considered overbought when the RSI is above 70.0 and oversold when below 30.0 (default settings)

How to add the RSI to your script?

Below you will find a short example of using the RSI in your script.

//Inputs
    // Create the input variable for the Length using an intInput
    rsiLen = intInput("RSI Length", 14)

    // Create the input variable for the overbought/oversold using a numInput
    upper = numInput("Overbought Level", 70.0)
    lower = numInput("Oversold Level", 30.0)

//indicator
    // Define the RSI using the candle CLOSE and the rsiLen Input
    RSI = rsi(close, rsiLen)

//Plot
    // Plot the RSI and the upper and lower threshold
    plot(RSI, "RSI", "#E45CFF", 2, PlotStyle.LINE, 0, false)
    plot(seriesOf(upper), "RSI upper", "#ffffff", 1, PlotStyle.LINE, 0, false)
    plot(seriesOf(lower), "RSI upper", "#ffffff", 1, PlotStyle.LINE, 0, false)

//Signal Push
    out(NEVER_ORDER)
RSI_2.PNG

The above image is how the plot should look on the chart. The pink line is the RSI line, and the 2 horizontal lines are the overbought and oversold areas.

How to use the RSI to generate buy and sell signals?

For the example I will use the default settings: Length = 14, overbought = 70.0, oversold = 30.0

The most commonly used method for the RSI, is to buy when the RSI crosses up through the oversold threshold, and to sell when the RSI crosses down through the overbought threshold.

This generally indicates a strong momentum change.

//Inputs
    // Create the input variable for the Length using an intInput
    rsiLen = intInput("RSI Length", 14)

    // Create the input variable for the overbought/oversold using a numInput
    upper = numInput("Overbought Level", 70.0)
    lower = numInput("Oversold Level", 30.0)

//indicator
    // Define the RSI using the candle CLOSE and the rsiLen Input
    RSI = rsi(close, rsiLen)

//Plot
    // Plot the RSI and the upper and lower threshold
    plot(RSI, "RSI", "#E45CFF", 2, PlotStyle.LINE, 0, false)
    plot(seriesOf(upper), "RSI upper", "#ffffff", 1, PlotStyle.LINE, 0, false)
    plot(seriesOf(lower), "RSI upper", "#ffffff", 1, PlotStyle.LINE, 0, false)

//Entry and Exit Conditions
    // Define the Entry condition of RSI crossing over the Lower Threshold
    buy = crossover(RSI, seriesOf(lower))

    // Define the Exit condition of RSI crossing under the upper Threshold
    sell = crossunder(RSI, seriesOf(upper))

//Signal Push
    // Here you will output your Entry and Exit signals
    out(signalIf(buy, sell))

Below is a screenshot of how your chart should look:

RSI_3.PNG

So now you have learnt what the RSI is, how to use it and how to put it in a script and generate signals from it.

Have fun scripting!

Disclaimer: The opinions expressed here are for general informational purposes only and are not intended to provide specific advice or recommendations for any specific security or investment product. You should never invest money that you cannot afford to lose. Before trading using complex financial products, please ensure to understand the risks involved. Past performance is no guarantee of future results.

Get started now

for free, in the cloud, wherever you are.

All investing involves risk, including the possible loss of all the money you invest, and past performance does not guarantee future performance. Historical returns expected returns, and probability projections are provided for informational and illustrative purposes, and may not reflect actual future performance.

Tuned is not a broker-dealer, exchange, custodian, wallet provider, or counterparty. Investing in cryptocurrency is highly speculative and volatile. Tuned is only suitable for investors who fully understand the risk of loss and may experience large drawdowns. Investors should never invest more than they can afford to lose.

Apple, the Apple logo, iPhone, and iPad are trademarks of Apple Inc., registered in the U.S. and other countries and regions. App Store is a service mark of Apple Inc.

Google Play and the Google Play logo are trademarks of Google LLC.