[Nic] Intraday Vix Labels
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © NicTheMajestic

//@version=5
indicator("[Nic] Vix Labels", overlay=true)

tblPos = input(position.bottom_right, "Position")
lblText = input(color.white, "Label Color")
lblBg = input(color.blue, "Label Bg")

TF2 = input.timeframe("30",  "TimeFrame2", group='TimeFrame Settings', options=['5', '15', '30', '60', '120', '4H', 'D', '2D', '5D', 'W', '2W', '4W', 'M', 'Q', 'Y'])
TF3 = input.timeframe("60",  "TimeFrame3", group='TimeFrame Settings', options=['5', '15', '30', '60', '120', '4H', 'D', '2D', '5D', 'W', '2W', '4W', 'M', 'Q', 'Y'])
TF4 = input.timeframe("120", "TimeFrame4", group='TimeFrame Settings', options=['5', '15', '30', '60', '120', '4H', 'D', '2D', '5D', 'W', '2W', '4W', 'M', 'Q', 'Y'])

DRAW1 = input.bool(false, "Draw Symbol1", group='Symbol Settings')
SYM1 = input.symbol("SPY", group='Symbol Settings')

DRAW2 = input.bool(false, "Draw Symbol2", group='Symbol Settings')
SYM2 = input.symbol("QQQ", group='Symbol Settings')

DRAW3 = input.bool(false, "Draw Symbol3", group='Symbol Settings')
SYM3 = input.symbol("IWM", group='Symbol Settings')

DRAW4 = input.bool(true, "Draw Symbol4", group='Symbol Settings')
SYM4 = input.symbol("PCC", group='Symbol Settings')

DRAW5 = input.bool(true, "Draw Symbol5", group='Symbol Settings')
SYM5 = input.symbol("VIX9D", group='Symbol Settings')

DRAW6 = input.bool(true, "Draw Symbol6", group='Symbol Settings')
SYM6 = input.symbol("VVIX", group='Symbol Settings')

var table tablo = table.new(tblPos,7,7,border_width=1,border_color=color.gray, frame_color=color.gray, frame_width=0)

// get change in Percentage values
f_getPercent(_p1, _p2) => (_p1 - _p2) * 100 / _p2

f_drawRow(_security, row) =>
    [o, _sec] = request.security(_security, 'D', [open, close])
    _pre = request.security(_security, 'D',close[1])
    _cha = _sec - _pre
    _pct = f_getPercent(_sec, _pre)
    _pct1 =  f_getPercent(_sec, o)
    table.cell(tablo,1,row,bgcolor=color.black,text_color=color.white, text=str.tostring(_sec))
    table.cell(tablo,2,row,bgcolor= (_pct  > 0 ? color.green : color.red), text_color=color.white, text=str.tostring(_pct, '#.##'))
    table.cell(tablo,3,row,bgcolor= (_pct1 > 0 ? color.green : color.red), text_color=color.white, text=str.tostring(_pct1, '#.##'))
    _pct2 = f_getPercent(_sec, request.security(_security, TF2, close[1]))
    table.cell(tablo,4,row,bgcolor= (_pct2 > 0 ? color.green : color.red), text_color=color.white, text=str.tostring(_pct2, '#.##'))
    _pct3 = f_getPercent(_sec, request.security(_security, TF3, close[1]))
    table.cell(tablo,5,row,bgcolor= (_pct3 > 0 ? color.green : color.red), text_color=color.white, text=str.tostring(_pct3, '#.##'))
    _pct4 = f_getPercent(_sec, request.security(_security, TF4, close[1]))
    table.cell(tablo,6,row,bgcolor= (_pct4 > 0 ? color.green : color.red), text_color=color.white, text=str.tostring(_pct4, '#.##'))
    
f_isfirstDay = ta.change(time("D"))

if barstate.islast
    table.cell(tablo,0,0,bgcolor=color.black,text_color=color.white, text="Symbol")
    table.cell(tablo,1,0,bgcolor=color.black,text_color=color.white, text="Price")
    table.cell(tablo,2,0,bgcolor=color.black,text_color=color.white, text="Day %")
    table.cell(tablo,3,0,bgcolor=color.black,text_color=color.white, text="Intra %")
    table.cell(tablo,4,0,bgcolor=color.black,text_color=color.white, text=str.tostring(TF2))
    table.cell(tablo,5,0,bgcolor=color.black,text_color=color.white, text=str.tostring(TF3))
    table.cell(tablo,6,0,bgcolor=color.black,text_color=color.white, text=str.tostring(TF4))
    if DRAW1
        table.cell(tablo,0,1,bgcolor=color.black,text_color=color.white, text=str.tostring(SYM1))
    if DRAW2
        table.cell(tablo,0,2,bgcolor=color.black,text_color=color.white, text=str.tostring(SYM2))
    if DRAW3
        table.cell(tablo,0,3,bgcolor=color.black,text_color=color.white, text=str.tostring(SYM3))
    if DRAW4
        table.cell(tablo,0,4,bgcolor=color.black,text_color=color.white, text=str.tostring(SYM4))
    if DRAW5
        table.cell(tablo,0,5,bgcolor=color.black,text_color=color.white, text=str.tostring(SYM5))
    if DRAW6
        table.cell(tablo,0,6,bgcolor=color.black,text_color=color.white, text=str.tostring(SYM6))
    
if DRAW1
    f_drawRow(SYM1, 1)
if DRAW2
    f_drawRow(SYM2, 2)
if DRAW3
    f_drawRow(SYM3, 3)
if DRAW4
    f_drawRow(SYM4, 4)
if DRAW5
    f_drawRow(SYM5, 5)
if DRAW6
    f_drawRow(SYM6, 6)
    
