Market Close Countdown
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5
indicator("Market Close Countdown", overlay=true)
head_tcolor = input(color.new(#ffffff,20),'Header Text Color',group='Table Style')
head_area = input(color.new(#232423,20),'Header Background Color',group='Table Style')
TextsizeOption = input.string(title="Label Size", options=["Auto", "Huge", "Large", "Normal", "Small", "Tiny"], defval="Auto",group='Table Style')
TextSize = (TextsizeOption == "Huge") ? size.huge :
     (TextsizeOption == "Large") ? size.large :
     (TextsizeOption == "Small") ? size.small :
     (TextsizeOption == "Tiny") ? size.tiny :
     (TextsizeOption == "Auto") ? size.auto :
     size.normal
	 
Table_loc = input.string(title="Table Position",options=["Top Right","Bottom Right","Top Left","Bottom Left", "Middle Right","Bottom Center"],defval="Bottom Right",group='Table Style')
var Table_position = Table_loc == 'Top Left' ? position.top_left :  Table_loc == 'Bottom Left' ? position.bottom_left :  Table_loc == 'Middle Right' ? position.middle_right :
                     Table_loc == 'Bottom Center' ? position.bottom_center :  Table_loc == 'Top Right' ? position.top_right : position.bottom_right

_r = barstate.isrealtime
_x = time_close
_y = timenow
[barval,timecloseval,timenowval] = request.security(syminfo.ticker,"D",[_r, _x, _y])
secLeft = (timecloseval - timenowval) / 1000
hoursleft = math.floor(secLeft / 3600)
minsleft =  math.floor (((secLeft / 3600) - math.floor(secLeft / 3600))*60)

var tb = table.new(Table_position,1,1,border_color=#000000,border_width = 1)
if barstate.islast
    table.cell(tb,0,0,str.tostring(hoursleft,'###')+":"+str.tostring(minsleft,'###'),text_color=head_tcolor,bgcolor=head_area,text_size=TextSize)

