Peer Performance - NIFTY36STOCKS
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AtulGoswami

//@version=5
indicator("Peer Performance", overlay=true)
cymbol=syminfo.tickerid

period=input.timeframe(defval="",title="Time Period")
//tablo = table.new(position = position.top_right, columns = 10, rows = 10, bgcolor = color.black, border_width = 2, frame_width=1,frame_color = color.white, border_color=color.white)
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////

//CEMENT INDUSTRY STOCKS

yearlyReturn= request.security(cymbol,period, ta.roc(close, 252))
yearlyReturn1= request.security("NSE:ACC",period, ta.roc(close, 252))
yearlyReturn2= request.security("NSE:ULTRACEMCO",period, ta.roc(close, 252))
yearlyReturn3= request.security("NSE:GRASIM",period, ta.roc(close, 252))
yearlyReturn4= request.security("NSE:AMBUJACEM",period, ta.roc(close, 252))
yearlyReturn5= request.security("NSE:SHREECEM",period, ta.roc(close, 252))

//AUTO INDUSTRY STOCKS

yr1= request.security("NSE:TATAMOTORS",period, ta.roc(close, 252))
yr2= request.security("NSE:BAJAJ_AUTO",period, ta.roc(close, 252))
yr3= request.security("NSE:HEROMOTOCO",period, ta.roc(close, 252))
yr4= request.security("NSE:EICHERMOT",period, ta.roc(close, 252))
yr5= request.security("NSE:MARUTI",period, ta.roc(close, 252))
yr6= request.security("NSE:M_M",period, ta.roc(close, 252))

//////////////////////////////////////////////////////////////////////////////
//BANKING INDUSTRY STOCKS

//yrB1= request.security(cymbol,period, ta.roc(close, 252))
yrB2= request.security("NSE:HDFCBANK",period, ta.roc(close, 252))
yrB3= request.security("NSE:ICICIBANK",period, ta.roc(close, 252))
yrB4= request.security("NSE:KOTAKBANK",period, ta.roc(close, 252))
yrB5= request.security("NSE:INDUSINDBK",period, ta.roc(close, 252))
yrB6= request.security("NSE:AXISBANK",period, ta.roc(close, 252))
yrB7= request.security("NSE:BANDHANBNK",period, ta.roc(close, 252))
yrB8= request.security("NSE:BANKBARODA",period, ta.roc(close, 252))
yrB9= request.security("NSE:SBIN",period, ta.roc(close, 252))
//////////////////////////////////////////////////////////////////////////////
//TECHNOLOGY INDUSTRY STOCKS

//yrT1= request.security(cymbol,period, ta.roc(close, 252))
yrT2= request.security("NSE:TCS",period, ta.roc(close, 252))
yrT3= request.security("NSE:INFY",period, ta.roc(close, 252))
yrT4= request.security("NSE:WIPRO",period, ta.roc(close, 252))
yrT5= request.security("NSE:MPHASIS",period, ta.roc(close, 252))
yrT6= request.security("NSE:HCLTECH",period, ta.roc(close, 252))
yrT7= request.security("NSE:TECHM",period, ta.roc(close, 252))
//yrT8= request.security("NSE:BANKBARODA",period, ta.roc(close, 252))

//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//OIL & GAS INDUSTRY STOCKS

yrO1= request.security(cymbol,period, ta.roc(close, 252))
yrO2= request.security("NSE:ADANIGREEN",period, ta.roc(close, 252))
yrO3= request.security("NSE:ATGL",period, ta.roc(close, 252))
yrO4= request.security("NSE:ADANITRANS",period, ta.roc(close, 252))
yrO5= request.security("NSE:RELIANCE",period, ta.roc(close, 252))
yrO6= request.security("NSE:ONGC",period, ta.roc(close, 252))
yrO7= request.security("NSE:POWERGRID",period, ta.roc(close, 252))
yrO8= request.security("NSE:COALINDIA",period, ta.roc(close, 252))
yrO9= request.security("NSE:TATAPOWER",period, ta.roc(close, 252))
yrO10= request.security("NSE:IOC",period, ta.roc(close, 252))
yrO11= request.security("NSE:NTPC",period, ta.roc(close, 252))

float[] oil=array.from(yrO1, yrO2, yrO3, yrO4, yrO5, yrO6, yrO7, yrO8, yrO9, yrO10, yrO11)

i1="Stocks"
i2="YearlyReturn"
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
// CEMENT STOCKS
if (cymbol=="NSE:ACC")  or (cymbol=="NSE:ULTRACEMCO") or (cymbol=="NSE:GRASIM")  or (cymbol=="NSE:AMBUJACEM")
    tablo = table.new(position = position.top_right, columns = 10, rows = 12, bgcolor = color.black, border_width = 2, frame_width=1,frame_color = color.white, border_color=color.white)
    
  

    txt1=str.tostring(math.round_to_mintick(yearlyReturn))
    txt2=str.tostring(math.round_to_mintick(yearlyReturn1))
    txt3=str.tostring(math.round_to_mintick(yearlyReturn2))
    txt4=str.tostring(math.round_to_mintick(yearlyReturn3))
    txt5=str.tostring(math.round_to_mintick(yearlyReturn4))
    txt6=str.tostring(math.round_to_mintick(yearlyReturn4))

    table.cell(tablo,0,0,text=i1,bgcolor = color.black, text_color = color.white)
    table.cell(tablo,1,0,text=i2,bgcolor = color.black, text_color = color.white)

    table.cell(tablo,0,1,text="ACC",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,2,text="ULTRATECH",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,3,text="GRASIM",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,4,text="AMBUJA",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,5,text="SHREECEMENT",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,1,1,text=txt1,bgcolor=yearlyReturn1>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,2,text=txt2,bgcolor=yearlyReturn2>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,3,text=txt3,bgcolor=yearlyReturn3>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,4,text=txt4,bgcolor=yearlyReturn4<0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,5,text=txt5,bgcolor=yearlyReturn5<0? color.green:color.red, text_color = color.white)


//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
// AUTO STOCKS

if (cymbol=="NSE:TATAMOTORS")  or (cymbol=="NSE:BAJAJ_AUTO") or (cymbol=="HEROMOTOCO")  or (cymbol=="NSE:EICHERMOT")or (cymbol=="NSE:MARUTI") or (cymbol=="NSE:M_M")
    tablo = table.new(position = position.top_right, columns = 10, rows = 10, bgcolor = color.black, border_width = 2, frame_width=1,frame_color = color.white, border_color=color.white)
    
    txt1=str.tostring(math.round_to_mintick(yr1))
    txt2=str.tostring(math.round_to_mintick(yr2))
    txt3=str.tostring(math.round_to_mintick(yr3))
    txt4=str.tostring(math.round_to_mintick(yr4))
    txt5=str.tostring(math.round_to_mintick(yr5))
    txt6=str.tostring(math.round_to_mintick(yr6))

    table.cell(tablo,0,0,text=i1,bgcolor = color.black, text_color = color.white)
    table.cell(tablo,1,0,text=i2,bgcolor = color.black, text_color = color.white)

    table.cell(tablo,0,1,text="TATAMOTORS",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,2,text="BAJAJ_AUTO",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,3,text="HEROMOTOCO",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,4,text="EICHERMOT",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,5,text="MARUTI",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,6,text="M&M",bgcolor= color.black, text_color = color.white)
  

    table.cell(tablo,1,1,text=txt1,bgcolor= yr1>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,2,text=txt2,bgcolor=yr2>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,3,text=txt3,bgcolor= yr3>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,4,text=txt4,bgcolor=yr4>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,5,text=txt5,bgcolor= yr5>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,6,text=txt6,bgcolor= yr6>0? color.green:color.red, text_color = color.white)
// if (cymbol=="NSE:TATAMOTOR")  or (cymbol=="NSE:BAJAJ_AUTO") or (cymbol=="HEROMOTOCO")  or (cymbol=="NSE:EICHERMOT") OR (cymbol=="NSE:MARUTI") or (cymbol=="NSE:M_M")


//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
// BANKING STOCKS

if (cymbol=="NSE:HDFCBANK")  or(cymbol=="SBIN") or (cymbol=="NSE:ICICIBANK") or (cymbol=="KOTAKBANK")  or (cymbol=="NSE:BANKBARODA")or (cymbol=="NSE:INDUSINDBK") or (cymbol=="NSE:AXISBANK") or (cymbol=="NSE:BANDHANBNK")
    tablo = table.new(position = position.top_right, columns = 10, rows = 10, bgcolor = color.black, border_width = 2, frame_width=1,frame_color = color.white, border_color=color.white)
    
    txt1=str.tostring(math.round_to_mintick(yrB2))
    txt2=str.tostring(math.round_to_mintick(yrB3))
    txt3=str.tostring(math.round_to_mintick(yrB4))
    txt4=str.tostring(math.round_to_mintick(yrB5))
    txt5=str.tostring(math.round_to_mintick(yrB6))
    txt6=str.tostring(math.round_to_mintick(yrB7))
    txt7=str.tostring(math.round_to_mintick(yrB8))
    txt8=str.tostring(math.round_to_mintick(yrB9))
    table.cell(tablo,0,0,text=i1,bgcolor = color.black, text_color = color.white)
    table.cell(tablo,1,0,text=i2,bgcolor = color.black, text_color = color.white)

    table.cell(tablo,0,1,text="HDFC BANK",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,2,text="ICICI BANK",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,3,text="KOTAK",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,4,text="INDUSIND BANK",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,5,text="AXIS BANK ",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,6,text="BANDHAN BANK ",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,7,text="BANK OF BARODA ",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,8,text="SBIN",bgcolor= color.black, text_color = color.white)

    table.cell(tablo,1,1,text=txt1,bgcolor= yrB2>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,2,text=txt2,bgcolor=yrB3>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,3,text=txt3,bgcolor= yrB4>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,4,text=txt4,bgcolor=yrB5>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,5,text=txt5,bgcolor= yrB6>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,6,text=txt6,bgcolor=yrB7>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,7,text=txt7,bgcolor= yrB8>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,8,text=txt8,bgcolor= yrB9>0? color.green:color.red, text_color = color.white)
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
// IT STOCKS

if (cymbol=="NSE:TCS")  or (cymbol=="NSE:INFY") or (cymbol=="WIPRO")  or (cymbol=="NSE:MPHASIS")or (cymbol=="NSE:HCLTECH") or (cymbol=="NSE:TECHM")
    tablo = table.new(position = position.top_right, columns = 10, rows = 12, bgcolor = color.black, border_width = 2, frame_width=1,frame_color = color.white, border_color=color.white)
    
    txt1=str.tostring(math.round_to_mintick(yrT2))
    txt2=str.tostring(math.round_to_mintick(yrT3))
    txt3=str.tostring(math.round_to_mintick(yrT4))
    txt4=str.tostring(math.round_to_mintick(yrT5))
    txt5=str.tostring(math.round_to_mintick(yrT6))
    txt6=str.tostring(math.round_to_mintick(yrT7))
    //txt7=str.tostring(math.round_to_mintick(yrB8))

    table.cell(tablo,0,0,text=i1,bgcolor = color.black, text_color = color.white)
    table.cell(tablo,1,0,text=i2,bgcolor = color.black, text_color = color.white)

    table.cell(tablo,0,1,text="TCS",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,2,text="INFOSYS",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,3,text="WIPRO",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,4,text="MPHASIS",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,5,text="HCLTECH ",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,6,text="TECHM ",bgcolor= color.black, text_color = color.white)
    //table.cell(tablo,0,7,text="BANK OF BARODA ",bgcolor= color.black, text_color = color.white)


    table.cell(tablo,1,1,text=txt1,bgcolor= yrT2>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,2,text=txt2,bgcolor=yrT3>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,3,text=txt3,bgcolor= yrT4>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,4,text=txt4,bgcolor=yrT5>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,5,text=txt5,bgcolor= yrT6>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,6,text=txt6,bgcolor=yrT7>0? color.green:color.red, text_color = color.white)
    //table.cell(tablo,1,7,text=txt7,bgcolor= yr5>0? color.green:color.red, text_color = color.white)


    /////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
// OIL -GAS & ENERGY STOCKS

if (cymbol=="NSE:ADANIGREEN")  or (cymbol=="NSE:ATGL") or (cymbol=="ADANITRANS")  or (cymbol=="NSE:RELIANCE")or (cymbol=="NSE:ONGC") or (cymbol=="NSE:COALINDIA") or (cymbol=="NSE:GAIL") or (cymbol=="NSE:POWERGRID")or (cymbol=="NSE:TATAPOWER")or (cymbol=="NSE:IOC")or (cymbol=="NSE:NTPC")
    tablo = table.new(position = position.top_right, columns = 10, rows = 15, bgcolor = color.black, border_width = 2, frame_width=1,frame_color = color.white, border_color=color.white)
    
    // for j=1 to 10 by 1
    //     txtj=str.tostring(math.round_to_mintick(array.get(oil, j)))

    txt1=str.tostring(math.round_to_mintick(yrO1))
    txt2=str.tostring(math.round_to_mintick(yrO2))
    txt3=str.tostring(math.round_to_mintick(yrO3))
    txt4=str.tostring(math.round_to_mintick(yrO4))
    txt5=str.tostring(math.round_to_mintick(yrO5))
    txt6=str.tostring(math.round_to_mintick(yrO6))
    txt7=str.tostring(math.round_to_mintick(yrO7))
    txt8=str.tostring(math.round_to_mintick(yrO8))
    txt9=str.tostring(math.round_to_mintick(yrO9))
    txt10=str.tostring(math.round_to_mintick(yrO10))
    txt11=str.tostring(math.round_to_mintick(yrO11))

    table.cell(tablo,0,0,text=i1,bgcolor = color.black, text_color = color.white)
    table.cell(tablo,1,0,text=i2,bgcolor = color.black, text_color = color.white)

    table.cell(tablo,0,1,text="ADANI GREEN",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,2,text="ATGL",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,3,text="ADANITRANSMISSION",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,4,text="RELIANCE",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,5,text="ONGC ",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,6,text="POWERGRID ",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,7,text="COALINDIA ",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,8,text="TATAPOWER ",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,9,text="IOC ",bgcolor= color.black, text_color = color.white)
    table.cell(tablo,0,10,text="NTPC ",bgcolor= color.black, text_color = color.white)
    //table.cell(tablo,0,11,text="NTPC ",bgcolor= color.black, text_color = color.white)
    //table.cell(tablo,0,7,text="BANK OF BARODA ",bgcolor= color.black, text_color = color.white)


    table.cell(tablo,1,1,text=txt2,bgcolor= yrO2>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,2,text=txt3,bgcolor=yrO3>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,3,text=txt4,bgcolor= yrO4>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,4,text=txt5,bgcolor=yrO5>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,5,text=txt6,bgcolor= yrO6>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,6,text=txt7,bgcolor=yrO7>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,7,text=txt8,bgcolor=yrO8>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,8,text=txt9,bgcolor=yrO9>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,9,text=txt10,bgcolor=yrO10>0? color.green:color.red, text_color = color.white)
    table.cell(tablo,1,10,text=txt11,bgcolor=yrO11>0? color.green:color.red, text_color = color.white)
    //table.cell(tablo,1,11,text=txt12,bgcolor=yrO11>0? color.green:color.red, text_color = color.white)
    //table.cell(tablo,1,7,text=txt7,bgcolor= yr5>0? color.green:color.red, text_color = color.white)