Rsi Intraday Short Strategy
Posted on August 17, 2022 by Quantplay Team ‐ 3 min read
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 -
Fig: Balance progression from Jan-31st to May-31st
Fig: Profit gained on backtested data from Jan-31st to May-31st
Strategy statistics -
Attribute | Year 2019 | Year 2020 | Year 2021 | Year 2022 | All (Combining all the years) |
---|---|---|---|---|---|
Total profit | 238608 | 59190 | 85577 | 159353 | 542728 |
Max drawdown | 45350 | 101281 | 85639 | 28757 | 144728 |
Sharpe ratio | 9.71 | 1.71 | 2.95 | 20.38 | 5.68 |
Max drawdown days | 34 | 49 | 68 | 10 | 283 |
Losing streak | 4 | 8 | 7 | 4 | 8 |
Winning streak | 6 | 5 | 7 | 8 | 8 |
Monthly pnl | 19884 | 4933 | 7131 | 31871 | 13237 |
Required exposure | 100000 | 100000 | 100000 | 100000 | 100000 |
Total signals | 1145 | 1139 | 1191 | 361 | 3836 |
Total trading days | 241 | 239 | 244 | 77 | 801 |
Success ratio | 0.52 | 0.48 | 0.51 | 0.60 | 0.52 |
Avg. pnl | 208 | 52 | 72 | 441 | 141 |
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.