Daily data info
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © GiovanniRielli
 
//@version=5
indicator('Daily data info' , overlay = true , precision = 0 , max_boxes_count = 500 , max_labels_count = 500 , max_lines_count = 500 , max_bars_back = 5000)


Timezone = 'America/New_York'
DOMD_D = (timeframe.isdaily)

Day_look_backs = input.int(defval = 500 , title = 'Day Look backs' , inline = 'back' , group = 'Data')
Dati_sum = input.bool(defval = false , title = '+ or' , inline = 'back' , group = 'Data')
Dati_per = input.bool(defval = false , title = '%' , inline = 'back' , group = 'Data')

labl_data = input.bool(defval = false , title = 'Label' , inline = 'Data' , group = 'Data')
Monday    = input.bool(defval = false , title = 'Monday' , inline = 'Data' , group = 'Data')
Tuesday   = input.bool(defval = false , title = 'Tuesday' , inline = 'Data' , group = 'Data')
Wednesday = input.bool(defval = false , title = 'Wednesday' , inline = 'Data' , group = 'Data')
Thursday  = input.bool(defval = false , title = 'Thursday' , inline = 'Data' , group = 'Data')
Friday    = input.bool(defval = false , title = 'Friday' , inline = 'Data' , group = 'Data')

highW = request.security(syminfo.tickerid, 'W', high , barmerge.gaps_off , barmerge.lookahead_on)
lowW  = request.security(syminfo.tickerid, 'W', low  , barmerge.gaps_off , barmerge.lookahead_on)
highD = request.security(syminfo.tickerid, 'D', high , barmerge.gaps_off , barmerge.lookahead_on)
lowD  = request.security(syminfo.tickerid, 'D', low  , barmerge.gaps_off , barmerge.lookahead_on)

//---High                                                                  //---Low
Highmonday    =  dayofweek(time_close) == dayofweek.monday    ? highD : na , Lowmonday    =  dayofweek(time_close) == dayofweek.monday    ? lowD : na
Hightuesday   =  dayofweek(time_close) == dayofweek.tuesday   ? highD : na , Lowtuesday   =  dayofweek(time_close) == dayofweek.tuesday   ? lowD : na
Highwednesday =  dayofweek(time_close) == dayofweek.wednesday ? highD : na , Lowwednesday =  dayofweek(time_close) == dayofweek.wednesday ? lowD : na
Highthursday  =  dayofweek(time_close) == dayofweek.thursday  ? highD : na , Lowthursday  =  dayofweek(time_close) == dayofweek.thursday  ? lowD : na
Highfriday    =  dayofweek(time_close) == dayofweek.friday    ? highD : na , Lowfriday    =  dayofweek(time_close) == dayofweek.friday    ? lowD : na

//---High Week                                    //---Low Week 
higMon = Highmonday    == math.max(high , highW) , lowMon = Lowmonday    == math.min(low , lowW)
higTue = Hightuesday   == math.max(high , highW) , lowTue = Lowtuesday   == math.min(low , lowW)
higWed = Highwednesday == math.max(high , highW) , lowWed = Lowwednesday == math.min(low , lowW)
higThu = Highthursday  == math.max(high , highW) , lowThu = Lowthursday  == math.min(low , lowW)
higFri = Highfriday    == math.max(high , highW) , lowFri = Lowfriday    == math.min(low , lowW)

//Label info
if DOMD_D and labl_data
    if Monday
        if higMon 
            label.new(x = bar_index , y = highD , text = 'Mon.' , xloc = xloc.bar_index , yloc = yloc.abovebar , color = color.rgb(33, 149, 243, 50) , style = label.style_label_down , textcolor = color.white , size = size.small)
        if lowMon 
            label.new(x = bar_index , y = lowD  , text = 'Mon.' , xloc = xloc.bar_index , yloc = yloc.belowbar , color = color.rgb(33, 149, 243, 50) , style = label.style_label_up , textcolor = color.white , size = size.small)
    if Tuesday
        if higTue 
            label.new(x = bar_index , y = highD , text = 'Tue.' , xloc = xloc.bar_index , yloc = yloc.abovebar , color = color.rgb(189, 236, 18, 50) , style = label.style_label_down , textcolor = color.white , size = size.small)
        if lowTue 
            label.new(x = bar_index , y = lowD , text = 'Tue.' , xloc = xloc.bar_index , yloc = yloc.belowbar , color = color.rgb(189, 236, 18, 50) , style = label.style_label_up , textcolor = color.white , size = size.small)
    if Wednesday
        if higWed 
            label.new(x = bar_index , y = highD , text = 'Wed.' , xloc = xloc.bar_index , yloc = yloc.abovebar , color = color.rgb(122, 15, 113, 50) , style = label.style_label_down , textcolor = color.white , size = size.small)
        if lowWed 
            label.new(x = bar_index , y = lowD , text = 'Wed.' , xloc = xloc.bar_index , yloc = yloc.belowbar , color = color.rgb(122, 15, 113, 50) , style = label.style_label_up , textcolor = color.white , size = size.small)
    if Thursday
        if higThu
            label.new(x = bar_index , y = highD , text = 'Thu.' , xloc = xloc.bar_index , yloc = yloc.abovebar , color = color.rgb(9, 67, 226, 50) , style = label.style_label_down , textcolor = color.white , size = size.small)
        if lowThu 
            label.new(x = bar_index , y = lowD , text = 'Thu.' , xloc = xloc.bar_index , yloc = yloc.belowbar , color = color.rgb(9, 67, 226, 50) , style = label.style_label_up , textcolor = color.white , size = size.small)
    if Friday
        if higFri 
            label.new(x = bar_index , y = highD , text = 'Fri.' , xloc = xloc.bar_index , yloc = yloc.abovebar , color = color.rgb(54, 69, 56, 50) , style = label.style_label_down , textcolor = color.white , size = size.small)
        if lowFri 
            label.new(x = bar_index , y = lowD , text = 'Fri.' , xloc = xloc.bar_index , yloc = yloc.belowbar , color = color.rgb(54, 69, 56, 50) , style = label.style_label_up , textcolor = color.white , size = size.small)


//----Tabel
show_TAB    = input.bool(defval = false , title = '' , inline = 'Tabel' , group = 'Tabel')
cho_Pos_TAB = input.string(title = '', defval = '←↓', options = ['↑', '←↑', '↑→', '↓', '←↓', '↓→'] , inline = 'Tabel' , group = 'Tabel')
posi_TAB  = cho_Pos_TAB == '↑→' ? position.top_right : cho_Pos_TAB == '←↑' ? position.top_left : cho_Pos_TAB == '↑→' ? position.top_right : cho_Pos_TAB == '↓' ? position.bottom_center : cho_Pos_TAB == '←↓' ? position.bottom_left : cho_Pos_TAB == '↓→' ? position.bottom_right : na
widt_TAB  = input(defval = 2 , title = '←→' , inline = 'Tabel' , group = 'Tabel')
heigt_TAB = input(defval = 1 , title = '↑' , inline = 'Tabel' , group = 'Tabel')
//---Text 
input_text_H = Dati_sum ? 'High + ' : Dati_per ? 'High % ' : na
input_text_L = Dati_sum ? 'Low + '  : Dati_per ? 'Low % ' : na

// Count Total   High                                  //             Low
count_H_Mon = math.sum(higMon ? 1 : 0 , Day_look_backs) , count_L_Mon = math.sum(lowMon ? 1 : 0 , Day_look_backs)
count_H_Tue = math.sum(higTue ? 1 : 0 , Day_look_backs) , count_L_Tue = math.sum(lowTue ? 1 : 0 , Day_look_backs)
count_H_Wed = math.sum(higWed ? 1 : 0 , Day_look_backs) , count_L_Wed = math.sum(lowWed ? 1 : 0 , Day_look_backs)
count_H_Thu = math.sum(higThu ? 1 : 0 , Day_look_backs) , count_L_Thu = math.sum(lowThu ? 1 : 0 , Day_look_backs)
count_H_Fri = math.sum(higFri ? 1 : 0 , Day_look_backs) , count_L_Fri = math.sum(lowFri ? 1 : 0 , Day_look_backs)

// % Total
per_H_Mon = count_H_Mon / Day_look_backs * 100 , per_L_Mon = count_L_Mon / Day_look_backs * 100
per_H_Tue = count_H_Tue / Day_look_backs * 100 , per_L_Tue = count_L_Tue / Day_look_backs * 100
per_H_Wed = count_H_Wed / Day_look_backs * 100 , per_L_Wed = count_L_Wed / Day_look_backs * 100
per_H_Thu = count_H_Thu / Day_look_backs * 100 , per_L_Thu = count_L_Thu / Day_look_backs * 100
per_H_Fri = count_H_Fri / Day_look_backs * 100 , per_L_Fri = count_L_Fri / Day_look_backs * 100


var table tableData = table.new(position = posi_TAB , columns = 6 , rows = 15 , frame_color = color.new(color.black, 0) , frame_width = 1, border_color = color.new(color.black, 0) , border_width = 1)

if show_TAB
    table.cell(tableData , 0 , 0 , str.tostring(Day_look_backs) , bgcolor = color.new(color.blue, 80) , tooltip = 'ToT count Bars')
    table.cell(tableData , 1 , 0 , input_text_H , bgcolor = color.new(color.blue, 80))
    table.cell(tableData , 2 , 0 , input_text_L , bgcolor = color.new(color.blue, 80))

    if Monday 
        table.cell(tableData , 0 , 1 , 'Mon.', bgcolor=color.new(color.yellow, 80))
        if Dati_sum and not Dati_per
            table.cell(tableData , 1 , 1 , str.tostring(count_H_Mon) , bgcolor = color.new(color.yellow, 80))
            table.cell(tableData , 2 , 1 , str.tostring(count_L_Mon) , bgcolor = color.new(color.yellow, 80))
        if Dati_per and not Dati_sum
            table.cell(tableData , 1 , 1 , str.tostring(per_H_Mon , format.percent) , bgcolor = color.new(color.yellow, 80))
            table.cell(tableData , 2 , 1 , str.tostring(per_L_Mon , format.percent) , bgcolor = color.new(color.yellow, 80))

    if Tuesday
        table.cell(tableData , 0 , 2 , 'Tue.', bgcolor=color.new(color.yellow, 80))
        if Dati_sum and not Dati_per
            table.cell(tableData , 1 , 2 , str.tostring(count_H_Tue), bgcolor=color.new(color.yellow, 80))
            table.cell(tableData , 2 , 2 , str.tostring(count_L_Tue), bgcolor=color.new(color.yellow, 80))
        if Dati_per and not Dati_sum
            table.cell(tableData , 1 , 2 , str.tostring(per_H_Tue , format.percent) , bgcolor = color.new(color.yellow, 80))
            table.cell(tableData , 2 , 2 , str.tostring(per_L_Tue , format.percent) , bgcolor = color.new(color.yellow, 80))
    
    if Wednesday
        table.cell(tableData , 0 , 3 , 'Wed.', bgcolor=color.new(color.yellow, 80))
        if Dati_sum and not Dati_per
            table.cell(tableData , 1 , 3 , str.tostring(count_H_Wed), bgcolor=color.new(color.yellow, 80))
            table.cell(tableData , 2 , 3 , str.tostring(count_L_Wed), bgcolor=color.new(color.yellow, 80))
        if Dati_per and not Dati_sum
            table.cell(tableData , 1 , 3 , str.tostring(per_H_Wed , format.percent) , bgcolor = color.new(color.yellow, 80))
            table.cell(tableData , 2 , 3 , str.tostring(per_L_Wed , format.percent) , bgcolor = color.new(color.yellow, 80))

    if Thursday
        table.cell(tableData , 0 , 4 , 'Thu.', bgcolor=color.new(color.yellow, 80))
        if Dati_sum and not Dati_per
            table.cell(tableData , 1 , 4 , str.tostring(count_H_Thu), bgcolor=color.new(color.yellow, 80))
            table.cell(tableData , 2 , 4 , str.tostring(count_L_Thu), bgcolor=color.new(color.yellow, 80))
        if Dati_per and not Dati_sum
            table.cell(tableData , 1 , 4 , str.tostring(per_H_Thu , format.percent) , bgcolor = color.new(color.yellow, 80))
            table.cell(tableData , 2 , 4 , str.tostring(per_L_Thu , format.percent) , bgcolor = color.new(color.yellow, 80))

    if Friday
        table.cell(tableData , 0 , 5 , 'Fri.', bgcolor=color.new(color.yellow, 80))
        if Dati_sum and not Dati_per
            table.cell(tableData , 1 , 5 , str.tostring(count_H_Fri), bgcolor=color.new(color.yellow, 80))
            table.cell(tableData , 2 , 5 , str.tostring(count_L_Fri), bgcolor=color.new(color.yellow, 80))
        if Dati_per and not Dati_sum
            table.cell(tableData , 1 , 5 , str.tostring(per_H_Fri , format.percent) , bgcolor = color.new(color.yellow, 80))
            table.cell(tableData , 2 , 5 , str.tostring(per_L_Fri , format.percent) , bgcolor = color.new(color.yellow, 80))
