Rsi Intraday Short Strategy

Posted on August 17, 2022 by Quantplay Team ‐ 3 min read

Rsi Intraday Short Strategy

RSI Intraday short strategy

What Is the Relative Strength Index (RSI)?

The relative strength index (RSI) was first introduced in the year 1978 in a book written by J.willes wilder. It 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 it oscillates in a range from 0 to 100.

Key details -

  • An RSI reading of 30 or below indicates an oversold stock.
  • An RSI reading of 70 or above indicates an overbought stock.

Let’s test the strategy by using Quantplay’s library -

  • Enter a trade at 9:30 AM (when the first 5-minute candle closes)
  • Exit the trade at 3:15 PM or whenever the stoploss triggers
  • Trade INR 1,00,000 in the stock
  • Filter stocks having RSI greater than 70 with Quantplay’s library
  • Pick top 5 stocks based on the previous day performance
  • Trade with a stop loss of 3%

Strategy code -

from quantplay.strategy.base import QuantplayAlgorithm
from quantplay.utils.constant import TickInterval
from quantplay.service import market
import numpy as np
import pandas as pd
import talib

class RSI(QuantplayAlgorithm):

    def __init__(self):
        self.interval = "5minute"
        self.entry_time = "09:25"
        self.exit_time = "15:15"
        self.exchange_to_trade_on = "NSE"
        self.stream_symbols_by_security_type = {"EQ": market.symbols(universe="FNO_STOCKS")}
        self.strategy_type = "intraday"
        self.strategy_tag = "rsi"

        super(RSI, self).__init__()

    def get_trades(self, market_data):
       trades = market.get_trades(market_data, self.entry_time)
       trades.loc[:, 'last_day_return'] = trades.close / trades.close.shift(1) - 1

       trades.loc[:, 'rsi'] = talib.RSI(trades.close, timeperiod=7)
       trades = trades[trades.rsi > 70]
       trades = trades.sort_values("last_day_return", ascending=False).groupby(['date']).head(5)

       trades.loc[:, 'tradingsymbol'] = trades.symbol
       trades.loc[:, "transaction_type"] = "SELL"
       trades.loc[:, "stoploss"] = 0.03
       trades.loc[:, "quantity"] = (100000/trades.close).astype(int)

       return trades
strategy = RSI()
strategy.validate()
res, trades = strategy.backtest()

Performance -

Image

Fig: Balance progression from Jan-31st to May-31st

Image

Fig: Profit gained on backtested data from Jan-31st to May-31st

Strategy statistics -

AttributeYear 2019Year 2020Year 2021Year 2022All (Combining all the years)
Total profit2386085919085577159353542728
Max drawdown453501012818563928757144728
Sharpe ratio9.711.712.9520.385.68
Max drawdown days34496810283
Losing streak48748
Winning streak65788
Monthly pnl19884493371313187113237
Required exposure100000100000100000100000100000
Total signals1145113911913613836
Total trading days24123924477801
Success ratio0.520.480.510.600.52
Avg. pnl2085272441141

Conclusion -

RSI is one of the most widely used and famous indicators of all time. But at the same time, one should always remember that using only RSI can be risky. One should always rely on more than one factor to improve his/her probablity of success in the markets.

We hope you enjoyed our blog about RSI. In our upcoming blogs, we will discuss the right market conditions to trade using RSI and improve the strategy results.

Follow us on your favorite social media app to get notified whenever we post strategies like this. You can also execute strategies like this within seconds by using Quantplay library.