Choppiness Index Tile
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vtrader321

//@version=5
indicator(title='Choppiness Index Tile', shorttitle='CHOP Tile', format=format.price, precision=2, overlay=true)

i_lowerBandColor = input.color(color.rgb(38, 166, 154), title='Lower Band Color (< 38.2)')
i_upperBandColor = input.color(color.rgb(240, 83, 80), title='Upper Band Color (> 61.8)')
i_midBandColor = input.color(color.rgb(33, 150, 243), title='Mid Band Color(Between 38.2 and 61.8)')
i_tableYpos = input.string('top', 'Panel position', inline='11', options=['top', 'middle', 'bottom'])
i_tableXpos = input.string('right', '', inline='11', options=['left', 'center', 'right'])
i_length = input.int(14, minval=1,title="Length")
_ci = 100 * math.log10(math.sum(ta.atr(1), i_length) / (ta.highest(i_length) - ta.lowest(i_length))) / math.log10(i_length)

var table _table = table.new(i_tableYpos + '_' + i_tableXpos, 1, 1, border_width=3)

color _cell_color = na
if _ci > 61.8
    _cell_color := i_upperBandColor
    _cell_color
else 
    if _ci < 38.2
        _cell_color := i_lowerBandColor
        _cell_color
    else 
        _cell_color := i_midBandColor
        _cell_color
_cellText = 'CHOP' + '\n' + str.tostring(_ci, '0.00')
table.cell(_table, 0, 0, _cellText, bgcolor=color.new(_cell_color, 80), text_color=_cell_color, text_size=size.normal)
plotchar(_ci, title="CHOP Tile", char="", location=location.top)