Weekday Change & Volume Average Table
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © noafarin

//@version=5
indicator("Weekday Change & Volume Average Table",overlay = true)
var is_replay = input.bool(false,"Is in Replay Mode?")
var avgTable = table.new(position = position.top_right, columns = 5, rows = 8, bgcolor = color.white, border_width = 1)
candle_time_percent = not is_replay ? (1-(time_close - timenow)/(time_close - time)) : 1

var sat = array.new_float()
var sat_vol = array.new_float()
var sun = array.new_float()
var sun_vol = array.new_float()
var mon = array.new_float()
var mon_vol = array.new_float()
var tue = array.new_float()
var tue_vol = array.new_float()
var wed = array.new_float()
var wed_vol = array.new_float()
var thu = array.new_float()
var thu_vol = array.new_float()
var fri = array.new_float()
var fri_vol = array.new_float()

dif = (high-low)*100/low
if dayofweek == dayofweek.saturday
    array.push(sat,dif)
    array.push(sat_vol,volume)
if dayofweek == dayofweek.sunday
    array.push(sun,dif)
    array.push(sun_vol,volume)
if dayofweek == dayofweek.monday
    array.push(mon,dif)
    array.push(mon_vol,volume)
if dayofweek == dayofweek.tuesday
    array.push(tue,dif)
    array.push(tue_vol,volume)
if dayofweek == dayofweek.wednesday
    array.push(wed,dif)
    array.push(wed_vol,volume)
if dayofweek == dayofweek.thursday
    array.push(thu,dif)
    array.push(thu_vol,volume)
if dayofweek == dayofweek.friday
    array.push(fri,dif)
    array.push(fri_vol,volume)


if bar_index == last_bar_index
    sat_avg = array.avg(sat)

    sat_hl_last = sat.size() == 0 ? 0 : array.last(sat)
    sat_vol_last = sat_vol.size() == 0 ? 0 : array.last(sat_vol)
    sat_vol_avg = array.avg(sat_vol)
    sun_avg = array.avg(sun)

    sun_hl_last = sun.size() == 0 ? 0 : array.last(sun)
    sun_vol_last = sun_vol.size() == 0 ? 0 : array.last(sun_vol)
    sun_vol_avg = array.avg(sun_vol)
    mon_avg = array.avg(mon)

    mon_hl_last = mon.size() == 0 ? 0 : array.last(mon)
    mon_vol_last = mon_vol.size() == 0 ? 0 : array.last(mon_vol)
    mon_vol_avg = array.avg(mon_vol)
    tue_avg = array.avg(tue)

    tue_hl_last = tue.size() == 0 ? 0 : array.last(tue)
    tue_vol_last = tue_vol.size() == 0 ? 0 : array.last(tue_vol)
    tue_vol_avg = array.avg(tue_vol)
    wed_avg = array.avg(wed)

    wed_hl_last = wed.size() == 0 ? 0 : array.last(wed)
    wed_vol_last = wed_vol.size() == 0 ? 0 : array.last(wed_vol)
    wed_vol_avg = array.avg(wed_vol)
    thu_avg = array.avg(thu)

    thu_hl_last = thu.size() == 0 ? 0 : array.last(thu)
    thu_vol_last = thu_vol.size() == 0 ? 0 : array.last(thu_vol)
    thu_vol_avg = array.avg(thu_vol)
    fri_avg = array.avg(fri)

    fri_hl_last = fri.size() == 0 ? 0 : array.last(fri)
    fri_vol_last = fri_vol.size() == 0 ? 0 : array.last(fri_vol)
    fri_vol_avg = array.avg(fri_vol)
    
    table.cell(table_id = avgTable, column = 1, row = 0, text = "HL Avg %", bgcolor=color.black,text_color = color.white,tooltip = "Average of (High-Low)/Low")
    table.cell(table_id = avgTable, column = 2, row = 0, text = "VOL Avg "+syminfo.basecurrency, bgcolor=color.black,text_color = color.white,tooltip = "Average of Volume")
    table.cell(table_id = avgTable, column = 3, row = 0, text = "Last HL %", bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 4, row = 0, text = "Last VOL "+syminfo.basecurrency, bgcolor=color.black,text_color = color.white)

    table.cell(table_id = avgTable, column = 0 , row = 1, text = "Saturday", bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 1 , row = 1, text = str.tostring(sat_avg,"#.##"), bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 2 , row = 1, text = str.tostring(sat_vol_avg,format.volume), bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 3 , row = 1, text = str.tostring(sat_hl_last,"#.##"), bgcolor= sat_hl_last > sat_avg ? color.green : color.red ,text_color = color.white)
    table.cell(table_id = avgTable, column = 4 , row = 1, text = str.tostring(sat_vol_last,format.volume), bgcolor= sat_vol_last > sat_vol_avg ? color.green : color.red ,text_color = color.white)
    table.cell(table_id = avgTable, column = 0 , row = 2, text = "Sunday", bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 1 , row = 2, text = str.tostring(sun_avg,"#.##"), bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 2 , row = 2, text = str.tostring(sun_vol_avg,format.volume), bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 3 , row = 2, text = str.tostring(sun_hl_last,"#.##"), bgcolor= sun_hl_last > sun_avg ? color.green : color.red ,text_color = color.white)
    table.cell(table_id = avgTable, column = 4 , row = 2, text = str.tostring(sun_vol_last,format.volume), bgcolor= sun_vol_last > sun_vol_avg ? color.green : color.red ,text_color = color.white)
    table.cell(table_id = avgTable, column = 0 , row = 3, text = "Monday", bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 1 , row = 3, text = str.tostring(mon_avg,"#.##"), bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 2 , row = 3, text = str.tostring(mon_vol_avg,format.volume), bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 3 , row = 3, text = str.tostring(mon_hl_last,"#.##"), bgcolor= mon_hl_last > mon_avg ? color.green : color.red ,text_color = color.white)
    table.cell(table_id = avgTable, column = 4 , row = 3, text = str.tostring(mon_vol_last,format.volume), bgcolor= mon_vol_last > mon_vol_avg ? color.green : color.red ,text_color = color.white)
    table.cell(table_id = avgTable, column = 0 , row = 4, text = "Tueday", bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 1 , row = 4, text = str.tostring(tue_avg,"#.##"), bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 2 , row = 4, text = str.tostring(tue_vol_avg,format.volume), bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 3 , row = 4, text = str.tostring(tue_hl_last,"#.##"), bgcolor= tue_hl_last > tue_avg ? color.green : color.red ,text_color = color.white)
    table.cell(table_id = avgTable, column = 4 , row = 4, text = str.tostring(tue_vol_last,format.volume), bgcolor= tue_vol_last > tue_vol_avg ? color.green : color.red ,text_color = color.white)
    table.cell(table_id = avgTable, column = 0 , row = 5, text = "Wednesday", bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 1 , row = 5, text = str.tostring(wed_avg,"#.##"), bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 2 , row = 5, text = str.tostring(wed_vol_avg,format.volume), bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 3 , row = 5, text = str.tostring(wed_hl_last,"#.##"), bgcolor= wed_hl_last > wed_avg ? color.green : color.red ,text_color = color.white)
    table.cell(table_id = avgTable, column = 4 , row = 5, text = str.tostring(wed_vol_last,format.volume), bgcolor= wed_vol_last > wed_vol_avg ? color.green : color.red ,text_color = color.white)
    table.cell(table_id = avgTable, column = 0 , row = 6, text = "Thursday", bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 1 , row = 6, text = str.tostring(thu_avg,"#.##"), bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 2 , row = 6, text = str.tostring(thu_vol_avg,format.volume), bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 3 , row = 6, text = str.tostring(thu_hl_last,"#.##"), bgcolor= thu_hl_last > thu_avg ? color.green : color.red ,text_color = color.white)
    table.cell(table_id = avgTable, column = 4 , row = 6, text = str.tostring(thu_vol_last,format.volume), bgcolor= thu_vol_last > thu_vol_avg ? color.green : color.red ,text_color = color.white)
    table.cell(table_id = avgTable, column = 0 , row = 7, text = "Friday", bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 1 , row = 7, text = str.tostring(fri_avg,"#.##"), bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 2 , row = 7, text = str.tostring(fri_vol_avg,format.volume), bgcolor=color.black,text_color = color.white)
    table.cell(table_id = avgTable, column = 3 , row = 7, text = str.tostring(fri_hl_last,"#.##"), bgcolor= fri_hl_last > fri_avg ? color.green : color.red ,text_color = color.white)
    table.cell(table_id = avgTable, column = 4 , row = 7, text = str.tostring(fri_vol_last,format.volume), bgcolor= fri_vol_last > fri_vol_avg ? color.green : color.red ,text_color = color.white)

    table.cell_set_bgcolor(table_id = avgTable, column = 0, row = (dayofweek+1)%7, bgcolor=color.yellow)
    table.cell_set_text_color(table_id = avgTable, column = 0, row = (dayofweek+1)%7,text_color = color.black)

    table.cell(table_id = avgTable, column = 0, row = 0,text = str.tostring(math.max(sat.size(),mon.size()))+" Candles" ,text_color = color.black,tooltip = "Max(Saturdays,Mondays) meaning the average is caculated based on how many candles for each weekday")