Market Performance Table
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © fyntrade
// Version 1.0 - 6 Oct 2023

//@version=5
indicator(title="Market Performance", shorttitle = "MP", overlay=true)

useT1 = input(true,"", inline = "1", group="Tickers")
t1 = input.symbol("AMEX:SPY","", inline = "1", group="Tickers")
useT2 = input(true,"", inline = "2", group="Tickers")
t2 = input.symbol("NASDAQ:QQQ" , "", inline = "2", group="Tickers")
useT3 = input(true,"", inline = "3", group="Tickers")
t3 = input.symbol("AMEX:IWM", "", inline = "3", group="Tickers")
useT4 = input(true,"", inline = "4", group="Tickers")
t4 = input.symbol("AMEX:IWO", "", inline = "4", group="Tickers")
useT5 = input(true,"", inline = "5", group="Tickers")
t5 = input.symbol("AMEX:IWC", "", inline = "5", group="Tickers")

dash_loc = input.string(defval = "Bottom Left", title = "Dashboard Location", options=["Top Left", "Top Center", "Top Right", "Middle Left", "Middle Center", "Middle Right", "Bottom Left", "Bottom Center", "Bottom Right"], group='Style Settings')
text_size = input.string(defval = "Small", title = "Dashboard Size", options=["Tiny", "Small", "Normal", "Large"], group='Style Settings')

var table_position = switch dash_loc
    "Top Left" => position.top_left
    "Top Center" =>  position.top_center
    "Top Right" => position.top_right
    "Middle Left" => position.middle_left
    "Middle Center" => position.middle_center
    "Middle Right" => position.middle_right
    "Bottom Left" => position.bottom_left
    "Bottom Center" => position.bottom_center
    "Bottom Right" => position.bottom_right

var table_text_size = switch text_size
    "Tiny" => size.tiny
    "Small" => size.small
    "Normal" => size.normal
    "Large" => size.large


cell_up = input(#4caf50,'Bullish Cell Color'  ,group='Style Settings')
cell_dn = input(#FF5252,'Bearish Cell Color'  ,group='Style Settings')
cell_neutral = input(#5d606b,'Neutral Cell Color'  ,group='Style Settings')
txt_col = input(color.silver,'Text/Frame Color'  ,group='Style Settings')
cell_transp = input.int(25,'Transparency'  ,minval=0  ,maxval=100  ,group='Style Settings')
  
f_calc(ticker) =>
    a_close = request.security(ticker,'1D',close)
    a_text = array.get(str.split(ticker, ':'),1)
    roc = ta.roc(a_close,1)/100
    sma200 = ta.sma(a_close,200)
    sma50 = ta.sma(a_close,50)
    sma20 = ta.sma(a_close,20)
    sma10 = ta.sma(a_close,10)
    ext50 = (a_close - sma50) / sma50
    [a_text, a_close, roc, a_close > sma50, a_close > sma20, a_close > sma10, sma10 > sma20, sma20 > sma50, sma50 > sma200, ext50]

var t = table.new(table_position,11,6,
  frame_color=txt_col,
  frame_width=1,
  border_color=txt_col,
  border_width=1)


[t1text, t1close, t1roc, t1sma50, t1sma20, t1sma10, t1sma10_20, t1sma20_50, t1sma50_200, t1ext50] = f_calc(t1)
[t2text, t2close, t2roc, t2sma50, t2sma20, t2sma10, t2sma10_20, t2sma20_50, t2sma50_200, t2ext50] = f_calc(t2)
[t3text, t3close, t3roc, t3sma50, t3sma20, t3sma10, t3sma10_20, t3sma20_50, t3sma50_200, t3ext50] = f_calc(t3)
[t4text, t4close, t4roc, t4sma50, t4sma20, t4sma10, t4sma10_20, t4sma20_50, t4sma50_200, t4ext50] = f_calc(t4)
[t5text, t5close, t5roc, t5sma50, t5sma20, t5sma10, t5sma10_20, t5sma20_50, t5sma50_200, t5ext50] = f_calc(t5)

if barstate.islast
    table.cell(t,1,0, 'Symbol' ,text_color=color.white,text_size=table_text_size,bgcolor=color.black)
    table.cell(t,2,0, 'Price ($)' ,text_color=color.white,text_size=table_text_size,bgcolor=color.black)
    table.cell(t,3,0, '1D change (%)' ,text_color=color.white,text_size=table_text_size,bgcolor=color.black)
    table.cell(t,4,0, '>50SMA' ,text_color=color.white,text_size=table_text_size,bgcolor=color.black)
    table.cell(t,5,0, '>20SMA' ,text_color=color.white,text_size=table_text_size,bgcolor=color.black)
    table.cell(t,6,0, '>10SMA' ,text_color=color.white,text_size=table_text_size,bgcolor=color.black)
    table.cell(t,7,0, '10>20SMA' ,text_color=color.white,text_size=table_text_size,bgcolor=color.black)
    table.cell(t,8,0, '20>50SMA' ,text_color=color.white,text_size=table_text_size,bgcolor=color.black)
    table.cell(t,9,0, '50>200SMA' ,text_color=color.white,text_size=table_text_size,bgcolor=color.black)
    table.cell(t,10,0, 'Ext 50SMA' ,text_color=color.white,text_size=table_text_size,bgcolor=color.black)

    if useT1
        table.cell(t,1,1, str.tostring(t1text) ,text_color=color.white,text_size=table_text_size,bgcolor=color.black)
        table.cell(t,2,1, str.tostring(t1close, '#.##'),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(cell_neutral,cell_transp))
        table.cell(t,3,1, str.tostring(t1roc, '#.##%'),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(cell_neutral,cell_transp))
        table.cell(t,4,1, str.tostring(t1sma50),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t1sma50 ? cell_up : cell_dn,cell_transp))
        table.cell(t,5,1, str.tostring(t1sma20),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t1sma20 ? cell_up : cell_dn,cell_transp))
        table.cell(t,6,1, str.tostring(t1sma10),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t1sma10 ? cell_up : cell_dn,cell_transp))
        table.cell(t,7,1, str.tostring(t1sma10_20),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t1sma10_20 ? cell_up : cell_dn,cell_transp))
        table.cell(t,8,1, str.tostring(t1sma20_50),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t1sma20_50 ? cell_up : cell_dn,cell_transp))
        table.cell(t,9,1, str.tostring(t1sma50_200),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t1sma50_200 ? cell_up : cell_dn,cell_transp))
        table.cell(t,10,1, str.tostring(t1ext50, '#.##%'),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(cell_neutral,cell_transp))

    if useT2
        table.cell(t,1,2, str.tostring(t2text),text_color=color.white,text_size=table_text_size,bgcolor=color.black)
        table.cell(t,2,2, str.tostring(t2close, '#.##'),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(cell_neutral,cell_transp))
        table.cell(t,3,2, str.tostring(t2roc, '#.##%'),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(cell_neutral,cell_transp))
        table.cell(t,4,2, str.tostring(t2sma50),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t2sma50 ? cell_up : cell_dn,cell_transp))
        table.cell(t,5,2, str.tostring(t2sma20),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t2sma20 ? cell_up : cell_dn,cell_transp))
        table.cell(t,6,2, str.tostring(t2sma10),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t2sma10 ? cell_up : cell_dn,cell_transp))
        table.cell(t,7,2, str.tostring(t2sma10_20),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t2sma10_20 ? cell_up : cell_dn,cell_transp))
        table.cell(t,8,2, str.tostring(t2sma20_50),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t2sma20_50 ? cell_up : cell_dn,cell_transp))
        table.cell(t,9,2, str.tostring(t2sma50_200),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t2sma50_200 ? cell_up : cell_dn,cell_transp))
        table.cell(t,10,2, str.tostring(t2ext50, '#.##%'),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(cell_neutral,cell_transp))

    if useT3
        table.cell(t,1,3, str.tostring(t3text),text_color=color.white,text_size=table_text_size,bgcolor=color.black)
        table.cell(t,2,3, str.tostring(t3close, '#.##'),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(cell_neutral,cell_transp))
        table.cell(t,3,3, str.tostring(t3roc, '#.##%'),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(cell_neutral,cell_transp))
        table.cell(t,4,3, str.tostring(t3sma50),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t3sma50 ? cell_up : cell_dn,cell_transp))
        table.cell(t,5,3, str.tostring(t3sma20),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t3sma20 ? cell_up : cell_dn,cell_transp))
        table.cell(t,6,3, str.tostring(t3sma10),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t3sma10 ? cell_up : cell_dn,cell_transp))
        table.cell(t,7,3, str.tostring(t3sma10_20),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t3sma10_20 ? cell_up : cell_dn,cell_transp))
        table.cell(t,8,3, str.tostring(t3sma20_50),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t3sma20_50 ? cell_up : cell_dn,cell_transp))
        table.cell(t,9,3, str.tostring(t3sma50_200),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t3sma50_200 ? cell_up : cell_dn,cell_transp))
        table.cell(t,10,3, str.tostring(t3ext50, '#.##%'),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(cell_neutral,cell_transp))

    if useT4
        table.cell(t,1,4, str.tostring(t4text),text_color=color.white,text_size=table_text_size,bgcolor=color.black)
        table.cell(t,2,4, str.tostring(t4close, '#.##'),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(cell_neutral,cell_transp))
        table.cell(t,3,4, str.tostring(t4roc, '#.##%'),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(cell_neutral,cell_transp))
        table.cell(t,4,4, str.tostring(t4sma50),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t4sma50 ? cell_up : cell_dn,cell_transp))
        table.cell(t,5,4, str.tostring(t4sma20),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t4sma20 ? cell_up : cell_dn,cell_transp))
        table.cell(t,6,4, str.tostring(t4sma10),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t4sma10 ? cell_up : cell_dn,cell_transp))
        table.cell(t,7,4, str.tostring(t4sma10_20),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t4sma10_20 ? cell_up : cell_dn,cell_transp))
        table.cell(t,8,4, str.tostring(t4sma20_50),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t4sma20_50 ? cell_up : cell_dn,cell_transp))
        table.cell(t,9,4, str.tostring(t4sma50_200),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t4sma50_200 ? cell_up : cell_dn,cell_transp))
        table.cell(t,10,4, str.tostring(t4ext50, '#.##%'),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(cell_neutral,cell_transp))

    if useT5
        table.cell(t,1,5, str.tostring(t5text),text_color=color.white,text_size=table_text_size,bgcolor=color.black)
        table.cell(t,2,5, str.tostring(t5close, '#.##'),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(cell_neutral,cell_transp))
        table.cell(t,3,5, str.tostring(t5roc, '#.##%'),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(cell_neutral,cell_transp))
        table.cell(t,4,5, str.tostring(t5sma50),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t5sma50 ? cell_up : cell_dn,cell_transp))
        table.cell(t,5,5, str.tostring(t5sma20),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t5sma20 ? cell_up : cell_dn,cell_transp))
        table.cell(t,6,5, str.tostring(t5sma10),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t5sma10 ? cell_up : cell_dn,cell_transp))
        table.cell(t,7,5, str.tostring(t5sma10_20),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t5sma10_20 ? cell_up : cell_dn,cell_transp))
        table.cell(t,8,5, str.tostring(t5sma20_50),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t5sma20_50 ? cell_up : cell_dn,cell_transp))
        table.cell(t,9,5, str.tostring(t5sma50_200),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(t5sma50_200 ? cell_up : cell_dn,cell_transp))
        table.cell(t,10,5, str.tostring(t5ext50, '#.##%'),text_color=txt_col,text_size=table_text_size, bgcolor=color.new(cell_neutral,cell_transp))
