Relative Daily Change% by SUMIT
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Sumit44812

// Disclaimer : **This is for educational purpose only.
// "Relative Daily Change%" Indicator

// The "Relative Daily Change%" indicator compares a stock's average daily price change percentage over the last 200 days with a chosen index. 
// It plots a colored curve. If the stock's change% is higher than the index, the curve is green, indicating it's doing better. Red means the stock is underperforming.


// This indicator is designed to compare the perfomrace of a stock with specific index (as selected) for last 200 candles.
// I use this during a breakout to see whether the stock is perfmorming well with comprison to it`s index.
// You can select Index from the list available in input
// **Line Color Green = Avg Change% per day of the stock is more than the Selected Index
// **Line Color White = Avg Change% per day of the stock is less than the Selected Index
// Disclaimer : **This is for educational purpose only.


//@version=5
indicator("Relative Daily Change% by SUMIT", overlay=false)

// SELECT THE APPLICABLE INDEX TO COMPARE WITH
symbol_index = input.string("NSE:NIFTY","REF INDEX", options=["NSE:NIFTY", "NSE:BANKNIFTY","NSE:CNXAUTO", "NSE:CNXFMCG", "NSE:NIFTY_HEALTHCARE", "NSE:CNXIT", "NSE:CNXMEDIA", "NSE:CNXMETAL", "NSE:CNXPHARMA", "NSE:CNXREALTY",  "NSE:NIFTY_OIL_AND_GAS"])

// Fetch the stock and index index data
stock_close = request.security(syminfo.tickerid, "D", close)
index_close = request.security(symbol_index, "D", close)

// Calculate the average percentage price change per day for last 200 candles (KEEP TIMEFRAME AS DAILY)
avgprice_change_stock = (((stock_close - stock_close[200]) / stock_close[200])/200) * 100
avgprice_change_index = (((index_close - index_close[200]) / index_close[200])/200) * 100


// If stock 200 day average price change is higher than selected index than the curve color will be green

lineColour = avgprice_change_stock > avgprice_change_index ? color.green : color.red

// Plot the curve
plot(avgprice_change_stock, title="AVG CHANGE% / DAY", color=lineColour, linewidth = 2)



