Opening Hour/Closing Hour Indices Statistics: high/low times; 5m
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

//Designed for use on US indices: ES, NQ (S&P, SPY; US100, etc etc)
// Idea is to get some statistics of time of high & time of low in both the opening hour (9:30-10:30am NY time) and the closing hour (15:00-1600 NY time)
// ES1! 77 days of history; SPX or SPY circa 250 days of history (all besed on 5min chart)
// Designed for use on 5min chart so we can get more meaningful comparison of % occurence of a certain time of high / time of low within said hour (i.e. group them in 5min buckets in stead of 1min buckets, for more meaningful statisitcal comparison)
// simplified using counters instead of looping array function =>> much faster load time with same results
// 31st March 2023
// © twingall

//@version=5
indicator(title='Opening Hour & Closing Hour Indices Statistics', shorttitle='Indices Stats: opening Hr & closing hr', overlay=true, max_bars_back =5000)

//user inputs:
showStats = input.bool(true, "show Statistics", group = 'Statistics, Sessions, Timezones', inline = '1',tooltip = "only works on the 5 minute timeframe")
showOpenHrStats = input.bool(true, "USER HOUR #1", group = 'Statistics, Sessions, Timezones', inline = '2')
showCloseHrStats = input.bool(true, "USER HOUR #2", group = 'Statistics, Sessions, Timezones', inline = '2')
showRealtime = input.bool(false, "// also show latest (last 2 sessions)",group = 'Statistics, Sessions, Timezones',inline ='3')
timeZone = input.string("America/New_York", group = 'Statistics, Sessions, Timezones', inline = '7', options =["America/New_York", "GMT-10", "GMT-9", "GMT-8", "GMT-7", "GMT-6", "GMT-5", "GMT-4", "GMT-3", "GMT-2", "GMT-1", "GMT", "GMT+1", "GMT+2", "GMT+3", "GMT+4", "GMT+5", "GMT+6", "GMT+7", "GMT+8", "GMT+9", "GMT+10", "GMT+11", "GMT+12", "GMT+13"], tooltip = "Note that when changing timezone; the data WILL represent the hour in the newly shifted vertical background highlighted areas; but the 'title time' in the statistics box will still show the New York Time\n\n you can verify this by toggling on 'also show latest (last 2 sessions)' amd checking timings/prices of recent highest/lowest of the highlighted hour")
showTable = input.bool(true, "Table", group = "Display Settings", inline ='1' )
tabPos = input.string(position.top_right, "|| Position:", group = "Display Settings", inline ='1', options = [ position.top_left, position.top_center, position.top_right, position.middle_left, position.middle_center, position.middle_right, position.bottom_left, position.bottom_center, position.bottom_right])
tabCol = input.color(color.new(color.gray, 74), "|| Bg Color:", group = "Display Settings", inline ='1')
txtCol = input.color(color.red, "|| txt Color:", group = "Display Settings", inline ='1')

showOpeningHour= input(defval=true, title='USER HOUR #1 background highlight',group = "Display Settings", inline = '4')
openingHrCol = input.color(color.new(color.fuchsia, 67), "",group = "Display Settings", inline = '4')
showClosingHour = input(defval=true, title='USER HOUR #2 background highlight',group = "Display Settings", inline = '5')
closingHrCol = input.color(color.new(color.blue, 67), "",group = "Display Settings", inline = '5')
precision = input.int(0, "decimal precision for %", minval = 0 ,group = "Display Settings", inline = '6')

is5min = timeframe.period == "5"
is1min = timeframe.period == "1"
    // ~~ highlight opening hour & closing hour
openHr = input.session("0930-1030", "User Hour #1 (format: 'XX:30-XX:30')", group = 'Statistics, Sessions, Timezones', inline = '5', options = ["0030-0130","0130-0230","0230-0330","0330-0430","0430-0530","0530-0630","0630-0730", "0730-0830", "0830-0930","0930-1030","1030-1130","1130-1230","1230-1330", "1330-1430", "1430-1530","1530-1630","1630-1730","1730-1830", "1830-1930", "1930-2030","2030-2130","2130-2230","2230-2330", "2330-0030"],
             tooltip = "Defaults to NY Opening hour (9:30-10:30am)\n\nCan be user-defined to any ##:30-##:30 hour of the day to find the high/low stats for that hour period")
openHrSess=time(timeframe.period, openHr, timeZone )
inOpenHr = nz(openHrSess)

closeHr = input.session("1500-1600", "User Hour #2 (format: 'XX:00-XX:00')", group = 'Statistics, Sessions, Timezones', inline = '6', options = ["0000-0100","0100-0200","0200-0300","0300-0400","0400-0500","0500-0600","0600-0700","0700-0800","0800-0900","0900-1000","1000-1100", "1100-1200","1200-1300","1300-1400","1400-1500","1500-1600", "1600-1700","1700-1800", "1800-1900","1900-2000","2000-2100","2100-2200","2200-2300", "2300-0000"],
             tooltip = "Defaults to NY Closing hour (15:00-16:00)\n\nCan be user-defined to any ##:00-##:00 hour of the day to find the high/low stats for that hour period")
closeHrSess=time(timeframe.period, closeHr, timeZone )
incloseHr = nz(closeHrSess)

timeTitleHr(string sess, int rank)=>
    string strTime = na
    if str.substring(sess, 2,4) == "00"
        strTime :=rank ==0?str.substring(sess, 0, 2) +":"+ str.substring(sess, 2,4):rank ==1?str.substring(sess, 0, 2) +":05":rank ==2?str.substring(sess, 0, 2) +":10":rank ==3?str.substring(sess, 0, 2) +":15":
         rank ==4?str.substring(sess, 0, 2) +":20":rank ==5?str.substring(sess, 0, 2)+":25":rank ==6?str.substring(sess, 0, 2) +":30":rank ==7?str.substring(sess, 0, 2) +":35": rank ==8?str.substring(sess, 0, 2) +":40":
         rank ==9?str.substring(sess, 0, 2) +":45":rank ==10?str.substring(sess, 0, 2) +":50":rank ==11?str.substring(sess, 0, 2) +":55":na
    if str.substring(sess, 2,4) == "30"
        strTime :=rank ==0?str.substring(sess, 0, 2) +":"+ str.substring(sess, 2,4):rank ==1?str.substring(sess, 0, 2) +":35":rank ==2?str.substring(sess, 0, 2) +":40":rank ==3?str.substring(sess, 0, 2) +":45":
         rank ==4?str.substring(sess, 0, 2) +":50":rank ==5?str.substring(sess, 0, 2)+":55":rank ==6?str.substring(sess, 5, 7) +":00":rank ==7?str.substring(sess, 5, 7) +":05": rank ==8?str.substring(sess, 5, 7) +":10":
         rank ==9?str.substring(sess, 5, 7) +":15":rank ==10?str.substring(sess, 5, 7) +":20":rank ==11?str.substring(sess, 5, 7) +":25":na
    strTime

bgcolor(showOpeningHour and (is5min or is1min) and inOpenHr? openingHrCol : na)
bgcolor(showClosingHour and (is5min or is1min) and incloseHr? closingHrCol : na)

openHrCond5 =  inOpenHr and inOpenHr [11] and not inOpenHr[12]
closeHrCond5 = showClosingHour and incloseHr and incloseHr[11] and not incloseHr[12] 
openHrCond1 =  inOpenHr and inOpenHr [59] and not inOpenHr[60]
closeHrCond1 = showClosingHour and incloseHr and incloseHr[59] and not incloseHr[60] 

highest5min = ta.highest(high, 12)
lowest5min = ta.lowest(low, 12)
    //only applying to 1min chart
highest1min = ta.highest(high, 60)
lowest1min = ta.lowest(low, 60)

var float h5op = na, var float h5cl = na
var float l5op = na, var float l5cl = na
var float h1op = na, var float h1cl = na
var float l1op = na, var float l1cl = na
var int th_5op = na, var int th_5cl = na
var int tl_5op = na, var int tl_5cl = na
var int th_1op = na, var int th_1cl = na
var int tl_1op = na, var int tl_1cl = na

offset_h5op = ta.highestbars(high,12)
offset_l5op = ta.lowestbars(low, 12)
offset_h1op = ta.highestbars(high,60)
offset_l1op = ta.lowestbars(low, 60)
offset_h5cl = ta.highestbars(high,12)
offset_l5cl = ta.lowestbars(low, 12)
offset_h1cl = ta.highestbars(high,60)
offset_l1cl = ta.lowestbars(low, 60)
_bar = timeframe.in_seconds(timeframe.period)*1000

var int cnt930h =0, var int cnt935h =0, var int cnt940h =0, var int cnt945h =0, var int cnt950h =0, var int cnt955h =0, var int cnt1000h =0, var int cnt1005h =0, var int cnt1010h =0, var int cnt1015h =0, var int cnt1020h =0, var int cnt1025h =0
var int cnt930l =0, var int cnt935l =0, var int cnt940l =0, var int cnt945l =0, var int cnt950l =0, var int cnt955l =0, var int cnt1000l =0, var int cnt1005l =0, var int cnt1010l =0, var int cnt1015l =0, var int cnt1020l =0, var int cnt1025l =0
var int cnt1500h =0, var int cnt1505h =0, var int cnt1510h =0, var int cnt1515h =0, var int cnt1520h =0, var int cnt1525h =0, var int cnt1530h =0, var int cnt1535h =0, var int cnt1540h =0, var int cnt1545h =0, var int cnt1550h =0, var int cnt1555h =0
var int cnt1500l =0, var int cnt1505l =0, var int cnt1510l =0, var int cnt1515l =0, var int cnt1520l =0, var int cnt1525l =0, var int cnt1530l =0, var int cnt1535l =0, var int cnt1540l =0, var int cnt1545l =0, var int cnt1550l =0, var int cnt1555l =0
var int cntTotOp =0, var int cntTotCl =0

if openHrCond5 and is5min
    cntTotOp+=1
    h5op:= highest5min
    th_5op:=time - (-offset_h5op*_bar)
    l5op:=lowest5min
    tl_5op:=time - (-offset_l5op*_bar)
        //increment the counters for highs
    cnt930h+=(offset_h5op==-11?1:0), cnt935h+=(offset_h5op==-10?1:0), cnt940h+=(offset_h5op==-9?1:0), cnt945h+=(offset_h5op==-8?1:0),cnt950h+=(offset_h5op==-7?1:0),cnt955h+=(offset_h5op==-6?1:0)
    cnt1000h+=(offset_h5op==-5?1:0),cnt1005h+=(offset_h5op==-4?1:0), cnt1010h+=(offset_h5op==-3?1:0), cnt1015h+=(offset_h5op==-2?1:0), cnt1020h+=(offset_h5op==-1?1:0),cnt1025h+=(offset_h5op==0?1:0)
        //increment the counters for lows
    cnt930l+=(offset_l5op==-11?1:0), cnt935l+=(offset_l5op==-10?1:0), cnt940l+=(offset_l5op==-9?1:0), cnt945l+=(offset_l5op==-8?1:0),cnt950l+=(offset_l5op==-7?1:0),cnt955l+=(offset_l5op==-6?1:0)
    cnt1000l+=(offset_l5op==-5?1:0),cnt1005l+=(offset_l5op==-4?1:0), cnt1010l+=(offset_l5op==-3?1:0), cnt1015l+=(offset_l5op==-2?1:0), cnt1020l+=(offset_l5op==-1?1:0),cnt1025l+=(offset_l5op==0?1:0)

if closeHrCond5 and is5min
    cntTotCl+=1
    h5cl:= highest5min
    th_5cl:=time - (-offset_h5cl*_bar)
    l5cl:=lowest5min
    tl_5cl:=time - (-offset_l5cl*_bar)
        //increment the counters for highs
    cnt1500h+=(offset_h5cl==-11?1:0), cnt1505h+=(offset_h5cl==-10?1:0), cnt1510h+=(offset_h5cl==-9?1:0), cnt1515h+=(offset_h5cl==-8?1:0),cnt1520h+=(offset_h5cl==-7?1:0),cnt1525h+=(offset_h5cl==-6?1:0)
    cnt1530h+=(offset_h5cl==-5?1:0),cnt1535h+=(offset_h5cl==-4?1:0), cnt1540h+=(offset_h5cl==-3?1:0), cnt1545h+=(offset_h5cl==-2?1:0), cnt1550h+=(offset_h5cl==-1?1:0),cnt1555h+=(offset_h5cl==0?1:0)
        //increment the counters for lows
    cnt1500l+=(offset_l5cl==-11?1:0), cnt1505l+=(offset_l5cl==-10?1:0), cnt1510l+=(offset_l5cl==-9?1:0), cnt1515l+=(offset_l5cl==-8?1:0),cnt1520l+=(offset_l5cl==-7?1:0),cnt1525l+=(offset_l5cl==-6?1:0)
    cnt1530l+=(offset_l5cl==-5?1:0),cnt1535l+=(offset_l5cl==-4?1:0), cnt1540l+=(offset_l5cl==-3?1:0), cnt1545l+=(offset_l5cl==-2?1:0), cnt1550l+=(offset_l5cl==-1?1:0),cnt1555l+=(offset_l5cl==0?1:0)

    //only for realtime on 1min chart, not for 5min chart statistics panel 
if openHrCond1 and is1min
    h1op:= highest1min
    th_1op:=time - (-offset_h1op*_bar)
    l1op:=lowest1min
    tl_1op:=time - (-offset_l1op*_bar)
if closeHrCond1 and is1min
    h1cl:= highest1min
    th_1cl:=time - (-offset_h1cl *_bar)
    l1cl:=lowest1min
    tl_1cl:=time - (-offset_l1cl *_bar)

    // Percent Function
pct(countSum, int _int)=>
    float pct = 0
    if countSum>0
        pct:= math.round((_int/countSum)*100,precision)
    pct

    ////  ~ Display Table ~
var Table = table.new(tabPos, columns = 8, rows =18, bgcolor = tabCol, border_width = 1)
if barstate.islast and showTable and showRealtime and (is5min or is1min)
    table.cell(Table, 1, 0, "User Hour #1\n" + openHr, text_color = txtCol, bgcolor = openingHrCol)
    table.cell(Table, 3, 0, "User Hour #2\n"+closeHr, text_color = txtCol, bgcolor = closingHrCol)
    table.cell(Table, 0, 1, "[latest] high =", text_color = txtCol, bgcolor = closingHrCol)
    table.cell(Table, 0, 2, "[latest]  low =", text_color = txtCol, bgcolor = closingHrCol)
    table.cell(Table, 2, 0, "  When?  ", text_color = txtCol)
    table.cell(Table, 4, 0, "  When?  ", text_color = txtCol)
    table.cell(Table, 0, 0, "Timeframe =\n"+ (is5min?"5 min":"1 min"), text_color = txtCol)
    if is5min
        table.cell(Table, 1, 1,str.tostring(h5op, format.mintick),bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 1, 2, str.tostring(l5op, format.mintick),bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 2, 1, str.format_time(th_5op , "HH:mm", "America/New_York"),bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 2, 2, str.format_time(tl_5op, "HH:mm", "America/New_York"),bgcolor = tabCol, text_color = txtCol)
  
        table.cell(Table, 3, 1, str.tostring(h5cl, format.mintick),bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 3, 2, str.tostring(l5cl, format.mintick),bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 4, 1, str.format_time(th_5cl, "HH:mm", "America/New_York"),bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 4, 2, str.format_time(tl_5cl, "HH:mm", "America/New_York"),bgcolor = tabCol, text_color = txtCol)
    if is1min
        table.cell(Table, 1, 1, str.tostring(h1op, format.mintick),bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 1, 2, "low = " +str.tostring(l1op, format.mintick),bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 2, 1, str.format_time(th_1op, "HH:mm", "America/New_York"),bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 2, 2, str.format_time(tl_1op, "HH:mm", "America/New_York"),bgcolor = tabCol, text_color = txtCol)

        table.cell(Table, 3, 1, str.tostring(h1cl, format.mintick),bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 3, 2, str.tostring(l1cl, format.mintick),bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 4, 1, str.format_time(th_1cl, "HH:mm", "America/New_York"),bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 4, 2, str.format_time(tl_1cl, "HH:mm", "America/New_York"),bgcolor = tabCol, text_color = txtCol)

if barstate.islast and showTable and is5min and showStats
    table.cell(Table, 0, 3, "~~STATISTICS~~\n"+ str.tostring(cntTotOp) + " = Trading Days of history | NYtime", text_color = txtCol, bgcolor = color.yellow, text_halign = text.align_center, text_size = size.large)
    table.merge_cells(Table, 0, 3, 5, 3)

    if showOpenHrStats
        table.cell(Table, 0, 4, "USER HOUR #1:",bgcolor = openingHrCol, text_color = txtCol)
        table.cell(Table, 1, 4, "  HIGH  ",bgcolor = color.new(color.green,70), text_color = txtCol)
        table.cell(Table, 2, 4, "  LOW  ",bgcolor = color.new(color.red,70), text_color = txtCol)
        table.cell(Table, 0, 5,  timeTitleHr(openHr, 0),bgcolor = openingHrCol, text_color = txtCol)
        table.cell(Table, 0, 6,  timeTitleHr(openHr, 1),bgcolor = openingHrCol, text_color = txtCol)
        table.cell(Table, 0, 7,  timeTitleHr(openHr, 2),bgcolor = openingHrCol, text_color = txtCol)
        table.cell(Table, 0, 8,  timeTitleHr(openHr, 3),bgcolor = openingHrCol, text_color = txtCol)
        table.cell(Table, 0, 9,  timeTitleHr(openHr, 4),bgcolor = openingHrCol, text_color = txtCol)
        table.cell(Table, 0, 10, timeTitleHr(openHr, 5),bgcolor = openingHrCol, text_color = txtCol)
        table.cell(Table, 0, 11, timeTitleHr(openHr, 6),bgcolor = openingHrCol, text_color = txtCol)
        table.cell(Table, 0, 12, timeTitleHr(openHr, 7),bgcolor = openingHrCol, text_color = txtCol)
        table.cell(Table, 0, 13, timeTitleHr(openHr, 8),bgcolor = openingHrCol, text_color = txtCol)
        table.cell(Table, 0, 14, timeTitleHr(openHr, 9),bgcolor = openingHrCol, text_color = txtCol)
        table.cell(Table, 0, 15, timeTitleHr(openHr, 10),bgcolor= openingHrCol, text_color = txtCol)
        table.cell(Table, 0, 16, timeTitleHr(openHr, 11),bgcolor= openingHrCol, text_color = txtCol)

        table.cell(Table, 1, 5,  str.tostring(pct(cntTotOp,cnt930h)) +" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 1, 6,  str.tostring(pct(cntTotOp,cnt935h)) +" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 1, 7,  str.tostring(pct(cntTotOp,cnt940h)) +" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 1, 8,  str.tostring(pct(cntTotOp,cnt945h)) +" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 1, 9,  str.tostring(pct(cntTotOp,cnt950h)) +" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 1, 10, str.tostring(pct(cntTotOp,cnt955h)) +" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 1, 11, str.tostring(pct(cntTotOp,cnt1000h))+" %",bgcolor = tabCol, text_color = txtCol) 
        table.cell(Table, 1, 12, str.tostring(pct(cntTotOp,cnt1005h))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 1, 13, str.tostring(pct(cntTotOp,cnt1010h))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 1, 14, str.tostring(pct(cntTotOp,cnt1015h))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 1, 15, str.tostring(pct(cntTotOp,cnt1020h))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 1, 16, str.tostring(pct(cntTotOp,cnt1025h))+" %",bgcolor = tabCol, text_color = txtCol)

        table.cell(Table, 2, 5,  str.tostring(pct(cntTotOp,cnt930l))+ " %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 2, 6,  str.tostring(pct(cntTotOp,cnt935l))+ " %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 2, 7,  str.tostring(pct(cntTotOp,cnt940l))+ " %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 2, 8,  str.tostring(pct(cntTotOp,cnt945l))+ " %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 2, 9,  str.tostring(pct(cntTotOp,cnt950l))+ " %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 2, 10, str.tostring(pct(cntTotOp,cnt955l))+ " %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 2, 11, str.tostring(pct(cntTotOp,cnt1000l))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 2, 12, str.tostring(pct(cntTotOp,cnt1005l))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 2, 13, str.tostring(pct(cntTotOp,cnt1010l))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 2, 14, str.tostring(pct(cntTotOp,cnt1015l))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 2, 15, str.tostring(pct(cntTotOp,cnt1020l))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 2, 16, str.tostring(pct(cntTotOp,cnt1025l))+" %",bgcolor = tabCol, text_color = txtCol)

    if showCloseHrStats
        table.cell(Table, 3, 4, "USER HOUR #2:",bgcolor = closingHrCol, text_color = txtCol)
        table.cell(Table, 4, 4, "  HIGH  ",bgcolor = color.new(color.green,70), text_color = txtCol)
        table.cell(Table, 5, 4, "  LOW  ",bgcolor = color.new(color.red,70), text_color = txtCol)
        table.cell(Table, 3, 5,  timeTitleHr(closeHr, 0), bgcolor = closingHrCol, text_color = txtCol)
        table.cell(Table, 3, 6,  timeTitleHr(closeHr, 1), bgcolor = closingHrCol, text_color = txtCol)
        table.cell(Table, 3, 7,  timeTitleHr(closeHr, 2), bgcolor = closingHrCol, text_color = txtCol)
        table.cell(Table, 3, 8,  timeTitleHr(closeHr, 3), bgcolor = closingHrCol, text_color = txtCol)
        table.cell(Table, 3, 9,  timeTitleHr(closeHr, 4), bgcolor = closingHrCol, text_color = txtCol)
        table.cell(Table, 3, 10, timeTitleHr(closeHr, 5), bgcolor = closingHrCol, text_color = txtCol)
        table.cell(Table, 3, 11, timeTitleHr(closeHr, 6), bgcolor = closingHrCol, text_color = txtCol)
        table.cell(Table, 3, 12, timeTitleHr(closeHr, 7), bgcolor = closingHrCol, text_color = txtCol)
        table.cell(Table, 3, 13, timeTitleHr(closeHr, 8), bgcolor = closingHrCol, text_color = txtCol)
        table.cell(Table, 3, 14, timeTitleHr(closeHr, 9), bgcolor = closingHrCol, text_color = txtCol)
        table.cell(Table, 3, 15, timeTitleHr(closeHr, 10),bgcolor = closingHrCol, text_color = txtCol)
        table.cell(Table, 3, 16, timeTitleHr(closeHr, 11),bgcolor = closingHrCol, text_color = txtCol)

        table.cell(Table, 4, 5,  str.tostring(pct(cntTotCl,cnt1500h))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 4, 6,  str.tostring(pct(cntTotCl,cnt1505h))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 4, 7,  str.tostring(pct(cntTotCl,cnt1510h))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 4, 8,  str.tostring(pct(cntTotCl,cnt1515h))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 4, 9,  str.tostring(pct(cntTotCl,cnt1520h))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 4, 10, str.tostring(pct(cntTotCl,cnt1525h))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 4, 11, str.tostring(pct(cntTotCl,cnt1530h))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 4, 12, str.tostring(pct(cntTotCl,cnt1535h))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 4, 13, str.tostring(pct(cntTotCl,cnt1540h))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 4, 14, str.tostring(pct(cntTotCl,cnt1545h))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 4, 15, str.tostring(pct(cntTotCl,cnt1550h))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 4, 16, str.tostring(pct(cntTotCl,cnt1555h))+" %",bgcolor = tabCol, text_color = txtCol)

        table.cell(Table, 5, 5,  str.tostring(pct(cntTotCl,cnt1500l))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 5, 6,  str.tostring(pct(cntTotCl,cnt1505l))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 5, 7,  str.tostring(pct(cntTotCl,cnt1510l))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 5, 8,  str.tostring(pct(cntTotCl,cnt1515l))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 5, 9,  str.tostring(pct(cntTotCl,cnt1520l))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 5, 10, str.tostring(pct(cntTotCl,cnt1525l))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 5, 11, str.tostring(pct(cntTotCl,cnt1530l))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 5, 12, str.tostring(pct(cntTotCl,cnt1535l))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 5, 13, str.tostring(pct(cntTotCl,cnt1540l))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 5, 14, str.tostring(pct(cntTotCl,cnt1545l))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 5, 15, str.tostring(pct(cntTotCl,cnt1550l))+" %",bgcolor = tabCol, text_color = txtCol)
        table.cell(Table, 5, 16, str.tostring(pct(cntTotCl,cnt1555l))+" %",bgcolor = tabCol, text_color = txtCol)