Relative Performance of stock against nifty & bank nifty
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Tradernawab

//@version=5
indicator("Nifty-Bank Nifty Relative Performance", overlay=false)

// Retrieve data for Nifty and Bank Nifty
nifty =request.security("NSE:NIFTY", timeframe.period, close)

banknifty = request.security("NSE:BANKNIFTY", "D", close)

// Calculate daily returns for Nifty and Bank Nifty
nifty_return = (nifty - nifty[1]) / nifty[1] * 100
banknifty_return = (banknifty - banknifty[1]) / banknifty[1] * 100

// Calculate average returns for Nifty and Bank Nifty
lookback=input.int(55,"lookback")
nifty_avg_return = ta.sma(nifty_return, lookback)
banknifty_avg_return = ta.sma(banknifty_return, lookback)

// Calculate relative performance
relative_performance = (close - ta.sma(close, lookback)) / ta.sma(close, lookback) * 100 - (nifty_avg_return + banknifty_avg_return) / 2

//calculate rsi
rsi=ta.rsi(close,14)

// Plot the relative performance and signal line
plot(relative_performance, "Relative Performance", color=color.green)
hline(0, "Signal Line", color=color.black)

//moving avg

interval=input.int(10,"interval")
moving_avg=ta.sma(relative_performance,interval)
plot(moving_avg)
//rsi calculation
Rsi=ta.rsi(close,14)

barcolor(relative_performance>moving_avg and Rsi>50 ?color.yellow:na)

barcolor(relative_performance<moving_avg and Rsi<50?color.rgb(74, 8, 228):na)