Jigga - Relative Strength - Sectors
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jigneshjc

//@version=5
indicator("Jigga - Relative Strength - Sectors",shorttitle="Jigga-RS-Sectors",overlay=false)



indexSymbol = input.symbol("NIFTY", title="Index Symbol", inline='IndexSymbol')
indexLength = input.int(10, minval=1, title="Length", inline='IndexSymbol')

//lableTops = input(false, title='------------------------   TOPS     ------------------------')

//lengthShowTop = input.int(10,minval=0,title="Top (n)" ,inline='TOP')
//lengthShowBottom = input.int(10,minval=0,title="Bottom (n)" ,inline='TOP')

lableSectors = input(false, title='------------------------   SECTORS     ------------------------')

showSectorIT = input.bool(true,title="IT", inline="Level1")
showSectorAUTO = input.bool(true,title="AUTO", inline="Level1")
showSectorMETAL = input.bool(true,title="METAL", inline="Level1")
showSectorPHARMA = input.bool(true,title="PHARMA", inline="Level2")
showSectorFMCG = input.bool(true,title="FMCG", inline="Level2")
showSectorCOMMODITIES = input.bool(true,title="COMMODITIES", inline="Level2")
showSectorINFRA = input.bool(false,title="INFRA", inline="Level3")
showSectorREALTY = input.bool(true,title="REALTY", inline="Level3")
showSectorMEDIA = input.bool(true,title="MEDIA", inline="Level3")

showSectorENERGY = input.bool(true,title="ENERGY", inline="Level4")
showSectorCONSUMPTION = input.bool(false,title="CONSUMPTION", inline="Level4")
showSectorSERVICE = input.bool(true,title="SERVICE", inline="Level4")

showSectorBANK = input.bool(false,title="BANK", inline="Level5")
showSectorFINANCE = input.bool(true,title="FINANCE", inline="Level5")
showSectorPSUBANK = input.bool(true,title="PSUBANK", inline="Level5")

line1 = hline(-2,title="Line1" ,color=color.black, linestyle=hline.style_dotted, linewidth=1)
line2 = hline(2,title="Line2" ,color=color.black, linestyle=hline.style_dotted, linewidth=1)
fill(line1, line2, color=color.gray, transp=90, title="Background")

getRelativeStrength(baseSymbolName, compareSymbolName, length) =>
    baseSymbol = request.security(baseSymbolName, timeframe.period, close)
    comparativeSymbol = request.security(compareSymbolName, timeframe.period, close)
    res = (baseSymbol / baseSymbol[length]) / (comparativeSymbol / comparativeSymbol[length]) - 1
    res * 100

f_draw_label(x, y, _text, _textcolor, _size) =>
    var label Label = na
    label.delete(Label)
    Label := label.new(x, y, _text, color=color.new(color.white, 20), textcolor=_textcolor, style=label.style_none, yloc=yloc.price, xloc=xloc.bar_time, size=_size)
    Label
    
    
//resBaseSymbol = getRelativeStrength(syminfo.tickerid,indexSymbol,indexLength)

resSectorIT = showSectorIT ? getRelativeStrength("CNXIT",indexSymbol,indexLength) : na
resSectorAUTO = showSectorAUTO ? getRelativeStrength("CNXAUTO",indexSymbol,indexLength) : na
resSectorMETAL = showSectorMETAL ? getRelativeStrength("CNXMETAL",indexSymbol,indexLength) : na
resSectorPHARMA = showSectorPHARMA ? getRelativeStrength("CNXPHARMA",indexSymbol,indexLength) : na
resSectorFMCG = showSectorFMCG ? getRelativeStrength("CNXFMCG",indexSymbol,indexLength) : na
resSectorCOMMODITIES = showSectorCOMMODITIES ? getRelativeStrength("CNXCOMMODITIES",indexSymbol,indexLength) : na

resSectorINFRA = showSectorINFRA ? getRelativeStrength("CNXINFRA",indexSymbol,indexLength) : na
resSectorREALTY = showSectorREALTY ? getRelativeStrength("CNXREALTY",indexSymbol,indexLength) : na
resSectorMEDIA = showSectorMEDIA ? getRelativeStrength("CNXMEDIA",indexSymbol,indexLength) : na

resSectorENERGY = showSectorENERGY ? getRelativeStrength("CNXENERGY",indexSymbol,indexLength) : na
resSectorCONSUMPTION = showSectorCONSUMPTION ? getRelativeStrength("CNXCONSUMPTION",indexSymbol,indexLength) : na
resSectorSERVICE = showSectorSERVICE ? getRelativeStrength("CNXSERVICE",indexSymbol,indexLength) : na

resSectorBANK = showSectorBANK ? getRelativeStrength("BANKNIFTY",indexSymbol,indexLength) : na
resSectorFINANCE = showSectorFINANCE ? getRelativeStrength("CNXFINANCE",indexSymbol,indexLength) : na
resSectorPSUBANK = showSectorPSUBANK ? getRelativeStrength("CNXPSUBANK",indexSymbol,indexLength) : na


if (showSectorIT)
    f_draw_label(timenow, resSectorIT[0], "IT", color.black, size.small)

if (showSectorAUTO)
    f_draw_label(timenow, resSectorAUTO[0], "AUTO", color.black, size.small)
    
if (showSectorMETAL)
    f_draw_label(timenow, resSectorMETAL[0], "METAL", color.black, size.small)

if (showSectorPHARMA)
    f_draw_label(timenow, resSectorPHARMA[0], "PHARMA", color.black, size.small)
    
if (showSectorFMCG)
    f_draw_label(timenow, resSectorFMCG[0], "FMCG", color.black, size.small)
    
if (showSectorCOMMODITIES)
    f_draw_label(timenow, resSectorCOMMODITIES[0], "COMMO", color.black, size.small)
    
if (showSectorINFRA)
    f_draw_label(timenow, resSectorINFRA[0], "ITNFRA", color.black, size.small)
    
if (showSectorREALTY)
    f_draw_label(timenow, resSectorREALTY[0], "REALTY", color.black, size.small)
    
if (showSectorMEDIA)
    f_draw_label(timenow, resSectorMEDIA[0], "MEDIA", color.black, size.small)
    
if (showSectorENERGY)
    f_draw_label(timenow, resSectorENERGY[0], "ENERGY", color.black, size.small)
    
if (showSectorCONSUMPTION)
    f_draw_label(timenow, resSectorCONSUMPTION[0], "CONSUM", color.black, size.small)
    
if (showSectorSERVICE)
    f_draw_label(timenow, resSectorSERVICE[0], "SERVICE", color.black, size.small)
    
if (showSectorBANK)
    f_draw_label(timenow, resSectorBANK[0], "BANK", color.black, size.small)
    
if (showSectorFINANCE)
    f_draw_label(timenow, resSectorFINANCE[0], "FINCE", color.black, size.small)
    
if (showSectorPSUBANK)
    f_draw_label(timenow, resSectorPSUBANK[0], "PSU", color.black, size.small)
    

plot(showSectorIT ? resSectorIT : na, title="IT", color=color.blue)
plot(showSectorAUTO? resSectorAUTO : na, title="AUTO", color=color.yellow)
plot(showSectorMETAL? resSectorMETAL : na, title="METAL", color=color.purple)
plot(showSectorPHARMA? resSectorPHARMA : na, title="PHARMA", color=color.red)
plot(showSectorFMCG? resSectorFMCG : na, title="FMCG", color=color.orange)
plot(showSectorCOMMODITIES? resSectorCOMMODITIES : na, title="COMMODITIES", color=color.black)

plot(showSectorINFRA ? resSectorINFRA : na, title="INFRA", color=color.maroon)
plot(showSectorREALTY ? resSectorREALTY : na, title="REALTY", color=color.purple)
plot(showSectorMEDIA ? resSectorMEDIA : na, title="MEDIA", color=color.green)

plot(showSectorENERGY ? resSectorENERGY : na, title="ENERGY", color=color.fuchsia)
plot(showSectorCONSUMPTION ? resSectorCONSUMPTION : na, title="CONSUM", color=color.lime)
plot(showSectorSERVICE ? resSectorSERVICE : na, title="SERVICE", color=color.navy)

plot(showSectorBANK ? resSectorBANK : na, title="BANK", color=color.teal)
plot(showSectorFINANCE ? resSectorFINANCE : na, title="FINANCE", color=color.aqua)
plot(showSectorPSUBANK ? resSectorPSUBANK : na, title="PSU", color=color.orange)