Rule of 16 - Lower
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © thebearfib
//
//@version=5
//
//a level of 1.8  - Tells vix pricing in for spx move
//According to the rule of 16, if the VIX is trading at 16, 
//then the SPX is estimated to see average daily moves up or down of 1% (because 16/16 = 1). 
//If the VIX is at 24, the daily moves might be around 1.5%, and at 32, the rule of 16 says the SPX might see 2% daily moves.
//
indicator("Rule of 16 - Lower", format= format.percent, precision = 2, overlay=false)

_barcol     = input.bool(defval = true, title = 'Color Bars',         group = '➤ Ｒｕｌｅ  ｏｆ  １６ ', inline='1')
_dip        = input.float(defval = 1.8, title = 'Buy The Dip Ratio',  group = '➤ Ｒｕｌｅ  ｏｆ  １６ ', inline='1')


_src        = close
_sN         = syminfo.ticker
_sym        = input.symbol("CBOE:VIX", " ", group = '➤ Ｓｙｍｂｏｌ', inline='1')
_tf         = input.timeframe("D", " ",     group = '➤ Ｓｙｍｂｏｌ', inline='1')
_cday       = request.security(_sym, _tf, _src) / 15.87
_pctMv      = _cday *16 

color _maxMove = _cday > _dip ? color.rgb(0, 255, 8) : color.rgb(111, 108, 108)

plot(_cday, title= 'vix plot',        color= _maxMove,                  linewidth=2,   style = plot.style_line,       display = display.all)

hline(1.8, title = 'SPX Threshold',   color=color.rgb(119, 120, 125), linewidth = 1, linestyle = hline.style_dashed,display = display.all)
hline(0,   title = 'Zeroline',        color=color.rgb(70, 70, 71),    linewidth = 5, linestyle = hline.style_solid, display = display.all)
//
// ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
// ————————————————————————————————— Inputs  ——————————————————————————————————————————————————————————————————————————————
// ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
//
_show         = input.bool(defval = true, title = "𝚂𝚑𝚘𝚠 & ", group='➤ Ｔａｂｌｅ', inline='1')
_position3c   = input.string("Top Center"," Position", options = ["Top Right", "Top Center", "Top Left", "Middle Right", "Middle Center", "Middle Left", "Bottom Right", "Bottom Center", "Bottom Left"], group='➤ Ｔａｂｌｅ', inline='1')
_fontSize1    = input.string("Normal","🗚 - Font Size", options = [ "Auto", "Tiny", "Small", "Normal", "Large", "Huge"])
_fontSize     = switch _fontSize1
    
    "Normal"    => size.normal
    "Auto"      => size.auto
    "Tiny"      => size.tiny
    "Small"     => size.small
    "Large"     => size.large
    "Huge"      => size.huge
//
// ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
// ————————————————————————————————— Inputs  ——————————————————————————————————————————————————————————————————————————————
// ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
//
tableposGo3 = switch _position3c
    
    "Top Right"     => position.top_right
    "Top Center"    => position.top_center
    "Top Left"      => position.top_left
    "Middle Right"  => position.middle_right
    "Middle Center" => position.middle_center
    "Middle Left"   => position.middle_left
    "Bottom Right"  => position.bottom_right
    "Bottom Center" => position.bottom_center
    "Bottom Left"   => position.bottom_left

if barstate.islast or barstate.islastconfirmedhistory
    var table tabu = table.new(tableposGo3, 99, 99,
      bgcolor = color.rgb(45, 44, 44,100),  
      frame_color=color.rgb(59, 58, 58,100),
      frame_width = 3,  
      border_color =color.rgb(19, 19, 19,100),
      border_width = 1)

    if _show
        table.cell(tabu, 1, 1, 'MOVE of SPX',text_halign = text.align_left,text_color = color.gray,text_size = _fontSize)
        table.cell(tabu, 2, 1, 'Annual:',text_halign = text.align_left,text_color = color.gray,text_size = _fontSize)
        table.cell(tabu, 3, 1, str.tostring(_pctMv, format.percent),text_halign = text.align_right,text_color = color.rgb(255, 255, 255),text_size = _fontSize)

        table.cell(tabu, 4, 1, 'Daily:',text_halign = text.align_left,text_color = color.gray,text_size = _fontSize)
        table.cell(tabu, 5, 1, str.tostring(_cday, format.percent),text_halign = text.align_right,text_color = color.rgb(255, 255, 255),text_size = _fontSize)

// barcolor(color, offset, editable, show_last, title, display)
barcolor( _barcol ? _maxMove : na, title='Color Bars - Show Above Threshold', display = display.all)
