Bogdan Ciocoiu - Looking Glass
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BogdanCiocoiu

//@version=5
 
// Original Description
// The script shows a multi-timeline suite of information for the current ticker. This information refers to configurable moving averages, RSI, Stochastic RSI, VWAP and TSI data. The timeframes reflected in the script vary from 1m to 1h. I recommend the tool for 3m scalping as it provides good visibility upwards.
// This is the updated version of the original script. Special thanks to SamAccountX for the support.
// Major updates compared to the v1 version include:
// - Being able to change the style of the lines, including width and colour
// - Being able to show/hide the table or specific columns/rows from within
// - Improvements in terms of naming the plots and shapes to ease traceability and managing settings
// - Optimised the previous revision by reducing the number of "request.security" calls, improving load and allowing room for more feature functionalities.
// - Allows repositioning the table subject to screen size and shape to suit the diverse type of terminals out there

// Originality and usefulness
// This tool is helpful because it helps users read a chart much quicker than if they were to navigate between timeframes. The colour coding indicates an accident/descendant trend between any two values (i.e. close vs MA1, MA1-MA2, RSI K vs RSI D, etc.).

// Open-source reuse
// https://www.tradingview.com/support/solutions/43000502589-moving-average/
// https://www.tradingview.com/support/solutions/43000502338-relative-strength-index-rsi/
// https://www.tradingview.com/support/solutions/43000502333-stochastic-rsi-stoch-rsi/
// https://www.tradingview.com/support/solutions/43000502018-volume-weighted-average-price-vwap/
// https://www.tradingview.com/support/solutions/43000592290-true-strength-indicator/

// ----------------------------------------------------------------------------------------
// Start
// ---------------------------------------------------------------------------------------- 
 
indicator("Bogdan Ciocoiu - Looking Glass", shorttitle="BC - Looking Glass", overlay=true)

_tf_1 = input(true, "Show TF 1m", inline="Timeframe")
_tf_3 = input(true, "3m", inline="Timeframe")
_tf_5 = input(true, "5m", inline="Timeframe")
_tf_15 = input(true, "15m", inline="Timeframe")
_tf_60 = input(true, "1h", inline="Timeframe")

_positive = input(color.green, "Positive", inline="Colour scheme")
_negative = input(color.red, "Negative", inline="Colour scheme")
_neutral = input(color.orange, "Neutral", inline="Colour scheme")

// ----------------------------------------------------------------------------------------
// Common library
// ----------------------------------------------------------------------------------------

_dec = str.length(str.tostring(syminfo.mintick[1]))-2

_trunc(_no, _dec) => int(_no * math.pow(10, _dec)) / math.pow (10, _dec)

_color_1(_no1, _no2)=>(_no1>_no2) ? color.new(_positive, 90) : color.new(_negative, 90)
_color_2(_no1, _no2)=>(_no1>_no2) ? color.new(_positive, 50) : color.new(_negative, 50)
_color_3(_no1, _no2, _no3)=>(_no1>_no2)?color.new(_negative, 90):(_no1 < _no3)?color.new(_positive, 90):color.new(_neutral, 90)
_color_4(_no1, _no2, _no3)=>(_no1>_no2)?color.new(_negative, 50):(_no1 < _no3)?color.new(_positive, 50):color.new(_neutral, 50)

_ma (_src, _len, _type) =>
    switch _type
        "SMA" => ta.sma(_src, _len)
        "EMA" => ta.ema(_src, _len)
        "WMA" => ta.wma(_src, _len)
        "VWMA" => ta.vwma(_src, _len)
        "SMMA" =>
            _ma = ta.sma ( _src, _len )
            _ma_final = 0.0
            _ma_final := na ( _ma_final[1] ) ? _ma : ( _ma_final[1] * ( _len - 1 ) + _src ) / _len
        
_vwap_compute(_vwap_src, _vwap_is_new_period) =>
	var float _vwap_sum_src_vol = na
	var float _vwap_sum_vol = na
    var float _vwap_sum_src_src_vol = na
	_vwap_sum_src_vol := _vwap_is_new_period ? _vwap_src * volume : _vwap_src * volume + _vwap_sum_src_vol[1]
	_vwap_sum_vol := _vwap_is_new_period ? volume : volume + _vwap_sum_vol[1]
	_vwap_sum_src_src_vol := _vwap_is_new_period ? volume * math.pow(_vwap_src, 2) : volume * math.pow(_vwap_src, 2) + _vwap_sum_src_vol[1]
	_vwap = _vwap_sum_src_vol / _vwap_sum_vol

// ----------------------------------------------------------------------------------------
// Dashboard
// ----------------------------------------------------------------------------------------

_dash_pos = input.string("bottom_right", title="Table position", options=["bottom_center", "bottom_left", "bottom_right", "middle_center", "middle_left", "middle_right", "top_center", "top_left", "top_right"], inline="Table setting") 

table _dash = table.new(_dash_pos, 25, 15, border_width=5)


// ----------------------------------------------------------------------------------------
// Three MA
// ----------------------------------------------------------------------------------------
_ma_style = input.string("SMMA", title="MA type", options=["SMA", "EMA", "WMA", "VWMA", "SMMA"], inline="MA engine")
_ma_src = input(close, title="", inline="MA engine")

_ma_src_1 = request.security(syminfo.tickerid, "1", _ma_src)
_ma_src_3 = request.security(syminfo.tickerid, "3", _ma_src)
_ma_src_5 = request.security(syminfo.tickerid, "5", _ma_src)
_ma_src_15 = request.security(syminfo.tickerid, "15", _ma_src)
_ma_src_60 = request.security(syminfo.tickerid, "60", _ma_src)

_ma1_show = input(true, "MA 1 length", inline="MA 1")
_ma1_len = input(21, "", inline="MA 1")
_ma1_col = input(color.green, title="", inline="MA 1")
_ma1_final = _ma(_ma_src, _ma1_len, _ma_style)
_ma1_final_1 = _ma(_ma_src_1, _ma1_len, _ma_style)
_ma1_final_3 = _ma(_ma_src_3, _ma1_len, _ma_style)
_ma1_final_5 = _ma(_ma_src_5, _ma1_len, _ma_style)
_ma1_final_15 = _ma(_ma_src_15, _ma1_len, _ma_style)
_ma1_final_60 = _ma(_ma_src_60, _ma1_len, _ma_style)

_ma2_show = input(true, "MA 2 length", inline="MA 2")
_ma2_len = input(50, "", inline="MA 2")
_ma2_col = input(color.orange, title="", inline="MA 2")
_ma2_final = _ma(_ma_src, _ma2_len, _ma_style)
_ma2_final_1 = _ma(_ma_src_1, _ma2_len, _ma_style)
_ma2_final_3 = _ma(_ma_src_3, _ma2_len, _ma_style)
_ma2_final_5 = _ma(_ma_src_5, _ma2_len, _ma_style)
_ma2_final_15 = _ma(_ma_src_15, _ma2_len, _ma_style)
_ma2_final_60 = _ma(_ma_src_60, _ma2_len, _ma_style)

_ma3_show = input(true, "MA 3 length", inline="MA 3")
_ma3_len = input(200, "", inline="MA 3")
_ma3_col = input(color.red, title="", inline="MA 3")
_ma3_final = _ma(_ma_src, _ma3_len, _ma_style)
_ma3_final_1 = _ma(_ma_src_1, _ma3_len, _ma_style)
_ma3_final_3 = _ma(_ma_src_3, _ma3_len, _ma_style)
_ma3_final_5 = _ma(_ma_src_5, _ma3_len, _ma_style)
_ma3_final_15 = _ma(_ma_src_15, _ma3_len, _ma_style)
_ma3_final_60 = _ma(_ma_src_60, _ma3_len, _ma_style)


// ----------------------------------------------------------------------------------------
// VWAP
// ----------------------------------------------------------------------------------------

_vwap_show = input(true, "Show VWAP", inline="VWAP engine")
_vwap_source = input(hlc3, title="", inline="VWAP engine")
_vwap_col = input(color.gray, title="", inline="VWAP engine")
_vwap_final = _vwap_compute(_vwap_source, ta.change(time("D")))

_vwap_final_1 = request.security(syminfo.tickerid, "1", _vwap_compute(_vwap_source, ta.change(time("D"))))
_vwap_final_3 = request.security(syminfo.tickerid, "3", _vwap_compute(_vwap_source, ta.change(time("D"))))
_vwap_final_5 = request.security(syminfo.tickerid, "5", _vwap_compute(_vwap_source, ta.change(time("D"))))
_vwap_final_15 = request.security(syminfo.tickerid, "15", _vwap_compute(_vwap_source, ta.change(time("D"))))
_vwap_final_60 = request.security(syminfo.tickerid, "60", _vwap_compute(_vwap_source, ta.change(time("D"))))

// ----------------------------------------------------------------------------------------
// TSI
// ----------------------------------------------------------------------------------------

_tsi_show = input(true, "Show TSI", inline="TSI engine")

_tsi_long = input(25, "", inline="TSI engine")
_tsi_short = input(13, "Short", inline="TSI engine")
_tsi_signal = input(13, "Signal", inline="TSI engine")

_tsi_price = close
_tsi_double_smooth(_tsi_src, _tsi_long, _tsi_short) =>
	_tsi_fist_smooth = ta.ema(_tsi_src, _tsi_long)
	ta.ema(_tsi_fist_smooth, _tsi_short)

_tsi_pc = ta.change(_tsi_price)
_tsi_double_smoothed_pc = _tsi_double_smooth(_tsi_pc, _tsi_long, _tsi_short)
_tsi_double_smoothed_abs_pc = _tsi_double_smooth(math.abs(_tsi_pc), _tsi_long, _tsi_short)
_tsi_val = 100 * (_tsi_double_smoothed_pc / _tsi_double_smoothed_abs_pc)
_tsi_val_signal = ta.ema(_tsi_val, _tsi_signal)
_tsi_val_signal_delta = _tsi_val - _tsi_val_signal

_tsi_val_1 = request.security(syminfo.tickerid, "1", 100 * (_tsi_double_smoothed_pc / _tsi_double_smoothed_abs_pc))
_tsi_val_1_signal = ta.ema(_tsi_val_1, _tsi_signal)
_tsi_val_1_signal_delta = _tsi_val_1 - _tsi_val_1_signal
_tsi_val_3 = request.security(syminfo.tickerid, "3", 100 * (_tsi_double_smoothed_pc / _tsi_double_smoothed_abs_pc))
_tsi_val_3_signal = ta.ema(_tsi_val_3, _tsi_signal)
_tsi_val_3_signal_delta = _tsi_val_3 - _tsi_val_3_signal
_tsi_val_5 = request.security(syminfo.tickerid, "5", 100 * (_tsi_double_smoothed_pc / _tsi_double_smoothed_abs_pc))
_tsi_val_5_signal = ta.ema(_tsi_val_5, _tsi_signal)
_tsi_val_5_signal_delta = _tsi_val_5 - _tsi_val_5_signal
_tsi_val_15 = request.security(syminfo.tickerid, "15", 100 * (_tsi_double_smoothed_pc / _tsi_double_smoothed_abs_pc))
_tsi_val_15_signal = ta.ema(_tsi_val_15, _tsi_signal)
_tsi_val_15_signal_delta = _tsi_val_15 - _tsi_val_15_signal
_tsi_val_60 = request.security(syminfo.tickerid, "60", 100 * (_tsi_double_smoothed_pc / _tsi_double_smoothed_abs_pc))
_tsi_val_60_signal = ta.ema(_tsi_val_60, _tsi_signal)
_tsi_val_60_signal_delta = _tsi_val_60 - _tsi_val_60_signal

// ----------------------------------------------------------------------------------------
// RSI
// ----------------------------------------------------------------------------------------

_rsi_show = input(true, "RSI", inline="RSI engine")

_rsi_len = input(14, "", inline="RSI engine")
_rsi_src = input(close, title="", inline="RSI engine")
_rsi_type = input.string("SMA", title="", options=["SMA", "EMA", "WMA", "VWMA", "SMMA"], inline="RSI engine")
_rsi_final = ta.rsi(_rsi_src, _rsi_len)

_rsi_final_1 = request.security(syminfo.tickerid, "1", ta.rsi(_rsi_src, _rsi_len))
_rsi_final_3 = request.security(syminfo.tickerid, "3", ta.rsi(_rsi_src, _rsi_len))
_rsi_final_5 = request.security(syminfo.tickerid, "5", ta.rsi(_rsi_src, _rsi_len))
_rsi_final_15 = request.security(syminfo.tickerid, "15", ta.rsi(_rsi_src, _rsi_len))
_rsi_final_60 = request.security(syminfo.tickerid, "60", ta.rsi(_rsi_src, _rsi_len))

// ----------------------------------------------------------------------------------------
// Stoch RSI
// ----------------------------------------------------------------------------------------

_s_rsi_show = input(true, "Show Stoch RSI", inline="Stoch RSI")

_s_rsi_smooth_k_d = input.int(3, "K/D", minval=1, inline="Stoch RSI")
_s_rsi_length = input.int(14, "Len", minval=1, inline="Stoch RSI")
_sto_RSI_src = input(close, title="", inline="Stoch RSI")
_sto_RSI_rsi = ta.rsi(_sto_RSI_src, _s_rsi_length)
_sto_RSI_k = ta.sma(ta.stoch(_sto_RSI_rsi, _sto_RSI_rsi, _sto_RSI_rsi, _s_rsi_length), _s_rsi_smooth_k_d)
_sto_RSI_d = ta.sma(_sto_RSI_k, _s_rsi_smooth_k_d)

_sto_RSI_k_1 = request.security(syminfo.tickerid, "1", ta.sma(ta.stoch(_sto_RSI_rsi, _sto_RSI_rsi, _sto_RSI_rsi, _s_rsi_length), _s_rsi_smooth_k_d))
_sto_RSI_d_1 = ta.sma(_sto_RSI_k_1, _s_rsi_smooth_k_d)
_sto_RSI_k_3 = request.security(syminfo.tickerid, "3", ta.sma(ta.stoch(_sto_RSI_rsi, _sto_RSI_rsi, _sto_RSI_rsi, _s_rsi_length), _s_rsi_smooth_k_d))
_sto_RSI_d_3 = ta.sma(_sto_RSI_k_3, _s_rsi_smooth_k_d)
_sto_RSI_k_5 = request.security(syminfo.tickerid, "5", ta.sma(ta.stoch(_sto_RSI_rsi, _sto_RSI_rsi, _sto_RSI_rsi, _s_rsi_length), _s_rsi_smooth_k_d))
_sto_RSI_d_5 = ta.sma(_sto_RSI_k_5, _s_rsi_smooth_k_d)
_sto_RSI_k_15 = request.security(syminfo.tickerid, "15", ta.sma(ta.stoch(_sto_RSI_rsi, _sto_RSI_rsi, _sto_RSI_rsi, _s_rsi_length), _s_rsi_smooth_k_d))
_sto_RSI_d_15 = ta.sma(_sto_RSI_k_15, _s_rsi_smooth_k_d)
_sto_RSI_k_60 = request.security(syminfo.tickerid, "60", ta.sma(ta.stoch(_sto_RSI_rsi, _sto_RSI_rsi, _sto_RSI_rsi, _s_rsi_length), _s_rsi_smooth_k_d))
_sto_RSI_d_60 = ta.sma(_sto_RSI_k_60, _s_rsi_smooth_k_d)

// ----------------------------------------------------------------------------------------
// Fractals
// ----------------------------------------------------------------------------------------

_fractals_show = input(true, "Show and enable Fractals periods", inline="Fractals engine")

_fractals_len = input(2, title="", inline="Fractals engine")

bool _fractals_above_down = true
bool _fractals_above_up0 = true
bool _fractals_above_up1 = true
bool _fractals_above_up2 = true
bool _fractals_above_up3 = true
bool _fractals_above_up4 = true

for i = 1 to _fractals_len
    _fractals_above_down := _fractals_above_down and (high[_fractals_len-i] < high[_fractals_len])
    _fractals_above_up0 := _fractals_above_up0 and (high[_fractals_len+i] < high[_fractals_len])
    _fractals_above_up1 := _fractals_above_up1 and (high[_fractals_len+1] <= high[_fractals_len] and high[_fractals_len+i + 1] < high[_fractals_len])
    _fractals_above_up2 := _fractals_above_up2 and (high[_fractals_len+1] <= high[_fractals_len] and high[_fractals_len+2] <= high[_fractals_len] and high[_fractals_len+i + 2] < high[_fractals_len])
    _fractals_above_up3 := _fractals_above_up3 and (high[_fractals_len+1] <= high[_fractals_len] and high[_fractals_len+2] <= high[_fractals_len] and high[_fractals_len+3] <= high[_fractals_len] and high[_fractals_len+i + 3] < high[_fractals_len])
    _fractals_above_up4 := _fractals_above_up4 and (high[_fractals_len+1] <= high[_fractals_len] and high[_fractals_len+2] <= high[_fractals_len] and high[_fractals_len+3] <= high[_fractals_len] and high[_fractals_len+4] <= high[_fractals_len] and high[_fractals_len+i + 4] < high[_fractals_len])
_fractals_above_trigger = _fractals_above_up0 or _fractals_above_up1 or _fractals_above_up2 or _fractals_above_up3 or _fractals_above_up4

_fractals_above = (_fractals_above_down and _fractals_above_trigger)

bool _fractals_below_down = true
bool _fractals_below_up0 = true
bool _fractals_below_up1 = true
bool _fractals_below_up2 = true
bool _fractals_below_up3 = true
bool _fractals_below_up4 = true

for i = 1 to _fractals_len
    _fractals_below_down := _fractals_below_down and (low[_fractals_len-i] > low[_fractals_len])
    _fractals_below_up0 := _fractals_below_up0 and (low[_fractals_len+i] > low[_fractals_len])
    _fractals_below_up1 := _fractals_below_up1 and (low[_fractals_len+1] >= low[_fractals_len] and low[_fractals_len+i + 1] > low[_fractals_len])
    _fractals_below_up2 := _fractals_below_up2 and (low[_fractals_len+1] >= low[_fractals_len] and low[_fractals_len+2] >= low[_fractals_len] and low[_fractals_len+i + 2] > low[_fractals_len])
    _fractals_below_up3 := _fractals_below_up3 and (low[_fractals_len+1] >= low[_fractals_len] and low[_fractals_len+2] >= low[_fractals_len] and low[_fractals_len+3] >= low[_fractals_len] and low[_fractals_len+i + 3] > low[_fractals_len])
    _fractals_below_up4 := _fractals_below_up4 and (low[_fractals_len+1] >= low[_fractals_len] and low[_fractals_len+2] >= low[_fractals_len] and low[_fractals_len+3] >= low[_fractals_len] and low[_fractals_len+4] >= low[_fractals_len] and low[_fractals_len+i + 4] > low[_fractals_len])
_fractals_below_trigger = _fractals_below_up0 or _fractals_below_up1 or _fractals_below_up2 or _fractals_below_up3 or _fractals_below_up4

_fractals_below = (_fractals_below_down and _fractals_below_trigger)

// ----------------------------------------------------------------------------------------
// Trend fill
// ----------------------------------------------------------------------------------------

_trend_fill_show = input(true, "Show trend fill", inline="Trend fill")

_trend_fill_pos = (close >= _ma1_final and _ma1_final >= _ma2_final and _ma2_final >= _ma3_final) ? true : false
_trend_fill_neg = (close <= _ma1_final and _ma1_final <= _ma2_final and _ma2_final <= _ma3_final) ? true : false

_trend_fill_pos_high_level = (close >= _ma3_final) ? true : false
_trend_fill_neg_high_level = (close <= _ma3_final) ? true : false

_trend_fill_color = _trend_fill_pos ? color.new(color.green, 90) : _trend_fill_neg ? color.new(color.red, 90) : na
_trend_fill_value = _trend_fill_pos ? _ma1_final : _trend_fill_neg ? _ma1_final : na

_trend_fill_plot_1 = plot(_trend_fill_show ? _trend_fill_value : na, "Fill 1", color=color.new(color.blue, 100), style=plot.style_line, linewidth=0)
_trend_fill_plot_2 = plot(_trend_fill_show ? _ma3_final : na, "Fill 2", color=color.new(color.blue, 100), style=plot.style_line, linewidth=0)

// ----------------------------------------------------------------------------------------
// Render
// ----------------------------------------------------------------------------------------
plot(_ma1_show ? _ma1_final : na, "MA 1", linewidth=1, style=plot.style_line, color=_ma1_col)
plot(_ma2_show ? _ma2_final : na, "MA 2", linewidth=1, style=plot.style_line, color=_ma2_col)
plot(_ma3_show ? _ma3_final : na, "MA 3", linewidth=3, style=plot.style_line, color=_ma3_col)

fill(_trend_fill_plot_1, _trend_fill_plot_2, color=_trend_fill_color, fillgaps=false)

plotshape(_fractals_show and _trend_fill_pos ? _fractals_below : na, "Fractals B1", style=shape.triangleup, location=location.belowbar, offset=-_fractals_len, color=color.new(color.green, 0), size=size.auto)
plotshape(_fractals_show and _trend_fill_neg ? _fractals_above : na, "Fractals A1", style=shape.triangledown, location=location.abovebar, offset=-_fractals_len, color=color.new(color.red, 0), size=size.auto)

plotshape(_fractals_show and _trend_fill_pos==false and _trend_fill_pos_high_level ? _fractals_below : na, "Fractals B2", style=shape.triangleup, location=location.belowbar, offset=-_fractals_len, color=color.new(color.gray, 0), size=size.auto)
plotshape(_fractals_show and _trend_fill_neg==false and _trend_fill_neg_high_level ? _fractals_above : na, "Fractals A2", style=shape.triangledown, location=location.abovebar, offset=-_fractals_len, color=color.new(color.gray, 0), size=size.auto)

plot(_vwap_show ? _vwap_final : na, "VWAP", linewidth=3, style=plot.style_line, color=color.new(_vwap_col, 50))

// ----------------------------------------------------------------------------------------
// Render table
// ----------------------------------------------------------------------------------------
if _tf_1 == true
    table.cell(_dash, 1, 2, "1",            text_color=(timeframe.period == "1") ? color.black : color.white, bgcolor=(timeframe.period == "1") ? color.new(color.green, 30) : color.black, width=1.5)
if _tf_3 == true
    table.cell(_dash, 1, 3, "3",            text_color=(timeframe.period == "3") ? color.black : color.white, bgcolor=(timeframe.period == "3") ? color.new(color.green, 30) : color.black)
if _tf_5 == true
    table.cell(_dash, 1, 4, "5",            text_color=(timeframe.period == "5") ? color.black : color.white, bgcolor=(timeframe.period == "5") ? color.new(color.green, 30) : color.black)
if _tf_15 == true
    table.cell(_dash, 1, 5, "15",           text_color=(timeframe.period == "15") ? color.black : color.white, bgcolor=(timeframe.period == "15") ? color.new(color.green, 30) : color.black)
if _tf_60 == true
    table.cell(_dash, 1, 6, "60",           text_color=(timeframe.period == "60") ? color.black : color.white, bgcolor=(timeframe.period == "60") ? color.new(color.green, 30) : color.black)
    
if _ma1_show == true and _ma2_show == true and _ma3_show == true 
    table.cell(_dash, 2, 1, "C-MA1",    text_color=color.white, bgcolor=color.new(_ma1_col, 30), width=2)
    table.cell(_dash, 3, 1, "C-MA2",    text_color=color.white, bgcolor=color.new(_ma2_col, 30), width=2)
    table.cell(_dash, 4, 1, "C-MA3",    text_color=color.white, bgcolor=color.new(_ma3_col, 30), width=2)
    table.cell(_dash, 5, 1, "MA1-2",  text_color=color.white, bgcolor=color.black, width=2)
    table.cell(_dash, 6, 1, "MA2-3",  text_color=color.white, bgcolor=color.black, width=2)
if _rsi_show == true
    table.cell(_dash, 7, 1, "RSI",      text_color=color.white, bgcolor=color.black, width=2)
if _s_rsi_show == true
    table.cell(_dash, 8, 1, "SRSI K",  text_color=color.white, bgcolor=color.black, width=2)
    table.cell(_dash, 9, 1, "D",        text_color=color.white, bgcolor=color.black, width=2)
if _vwap_show == true
    table.cell(_dash, 10, 1, "VWAP",    text_color=color.white, bgcolor=color.new(_vwap_col, 30), width=2)
if _tsi_show == true
    table.cell(_dash, 11, 1, "TSI",     text_color=color.white, bgcolor=color.black, width=2)
    table.cell(_dash, 12, 1, "Signal",  text_color=color.white, bgcolor=color.black, width=2)
    table.cell(_dash, 13, 1, "Δ",       text_color=color.white, bgcolor=color.black, width=1.5)

if _ma1_show == true and _ma2_show == true and _ma3_show == true and _tf_1 == true
    table.cell(_dash, 2, 2, str.tostring(_trunc(close - _ma1_final_1, _dec)),           text_color=_color_2(close, _ma1_final_1),           bgcolor=_color_1(close, _ma1_final_1))
    table.cell(_dash, 3, 2, str.tostring(_trunc(close - _ma2_final_1, _dec)),           text_color=_color_2(close, _ma2_final_1),           bgcolor=_color_1(close, _ma2_final_1))
    table.cell(_dash, 4, 2, str.tostring(_trunc(close - _ma3_final_1, _dec)),           text_color=_color_2(close, _ma3_final_1),           bgcolor=_color_1(close, _ma3_final_1))
    table.cell(_dash, 5, 2, str.tostring(_trunc(_ma1_final_1 - _ma2_final_1, _dec)),    text_color=_color_2(_ma1_final_1, _ma2_final_1),    bgcolor=_color_1(_ma1_final_1, _ma2_final_1))
    table.cell(_dash, 6, 2, str.tostring(_trunc(_ma2_final_1 - _ma3_final_1, _dec)),    text_color=_color_2(_ma2_final_1, _ma3_final_1),    bgcolor=_color_1(_ma2_final_1, _ma3_final_1))
    
if _ma1_show == true and _ma2_show == true and _ma3_show == true and _tf_3 == true
    table.cell(_dash, 2, 3, str.tostring(_trunc(close - _ma1_final_3, _dec)),           text_color=_color_2(close, _ma1_final_3),           bgcolor=_color_1(close, _ma1_final_3))
    table.cell(_dash, 3, 3, str.tostring(_trunc(close - _ma2_final_3, _dec)),           text_color=_color_2(close, _ma2_final_3),           bgcolor=_color_1(close, _ma2_final_3))
    table.cell(_dash, 4, 3, str.tostring(_trunc(close - _ma3_final_3, _dec)),           text_color=_color_2(close, _ma3_final_3),           bgcolor=_color_1(close, _ma3_final_3))
    table.cell(_dash, 5, 3, str.tostring(_trunc(_ma1_final_3 - _ma2_final_3, _dec)),    text_color=_color_2(_ma1_final_3, _ma2_final_3),    bgcolor=_color_1(_ma1_final_3, _ma2_final_3))
    table.cell(_dash, 6, 3, str.tostring(_trunc(_ma2_final_3 - _ma3_final_3, _dec)),    text_color=_color_2(_ma2_final_3, _ma3_final_3),    bgcolor=_color_1(_ma2_final_3, _ma3_final_3))
    
if _ma1_show == true and _ma2_show == true and _ma3_show == true and _tf_5 == true
    table.cell(_dash, 2, 4, str.tostring(_trunc(close - _ma1_final_5, _dec)),           text_color=_color_2(close, _ma1_final_5),           bgcolor=_color_1(close, _ma1_final_5))
    table.cell(_dash, 3, 4, str.tostring(_trunc(close - _ma2_final_5, _dec)),           text_color=_color_2(close, _ma2_final_5),           bgcolor=_color_1(close, _ma2_final_5))
    table.cell(_dash, 4, 4, str.tostring(_trunc(close - _ma3_final_5, _dec)),           text_color=_color_2(close, _ma3_final_5),           bgcolor=_color_1(close, _ma3_final_5))
    table.cell(_dash, 5, 4, str.tostring(_trunc(_ma1_final_5 - _ma2_final_5, _dec)),    text_color=_color_2(_ma1_final_5, _ma2_final_5),    bgcolor=_color_1(_ma1_final_5, _ma2_final_5))
    table.cell(_dash, 6, 4, str.tostring(_trunc(_ma2_final_5 - _ma3_final_5, _dec)),    text_color=_color_2(_ma2_final_5, _ma3_final_5),    bgcolor=_color_1(_ma2_final_5, _ma3_final_5))

if _ma1_show == true and _ma2_show == true and _ma3_show == true and _tf_15 == true    
    table.cell(_dash, 2, 5, str.tostring(_trunc(close - _ma1_final_15, _dec)),          text_color=_color_2(close, _ma1_final_15),          bgcolor=_color_1(close, _ma1_final_15))
    table.cell(_dash, 3, 5, str.tostring(_trunc(close - _ma2_final_15, _dec)),          text_color=_color_2(close, _ma2_final_15),          bgcolor=_color_1(close, _ma2_final_15))
    table.cell(_dash, 4, 5, str.tostring(_trunc(close - _ma3_final_15, _dec)),          text_color=_color_2(close, _ma3_final_15),          bgcolor=_color_1(close, _ma3_final_15))
    table.cell(_dash, 5, 5, str.tostring(_trunc(_ma1_final_15 - _ma2_final_15, _dec)),  text_color=_color_2(_ma1_final_15, _ma2_final_15),  bgcolor=_color_1(_ma1_final_15, _ma2_final_15))
    table.cell(_dash, 6, 5, str.tostring(_trunc(_ma2_final_15 - _ma3_final_15, _dec)),  text_color=_color_2(_ma2_final_15, _ma3_final_15),  bgcolor=_color_1(_ma2_final_15, _ma3_final_15))
    
if _ma1_show == true and _ma2_show == true and _ma3_show == true and _tf_60 == true
    table.cell(_dash, 2, 6, str.tostring(_trunc(close - _ma1_final_60, _dec)),          text_color=_color_2(close, _ma1_final_60),          bgcolor=_color_1(close, _ma1_final_60))
    table.cell(_dash, 3, 6, str.tostring(_trunc(close - _ma2_final_60, _dec)),          text_color=_color_2(close, _ma2_final_60),          bgcolor=_color_1(close, _ma2_final_60))
    table.cell(_dash, 4, 6, str.tostring(_trunc(close - _ma3_final_60, _dec)),          text_color=_color_2(close, _ma3_final_60),          bgcolor=_color_1(close, _ma3_final_60))
    table.cell(_dash, 5, 6, str.tostring(_trunc(_ma1_final_60 - _ma2_final_60, _dec)),  text_color=_color_2(_ma1_final_60, _ma2_final_60),  bgcolor=_color_1(_ma1_final_60, _ma2_final_60))
    table.cell(_dash, 6, 6, str.tostring(_trunc(_ma2_final_60 - _ma3_final_60, _dec)),  text_color=_color_2(_ma2_final_60, _ma3_final_60),  bgcolor=_color_1(_ma2_final_60, _ma3_final_60))

if _rsi_show == true and _tf_1 == true
    table.cell(_dash, 7, 2, str.tostring(math.round(_rsi_final_1)),                     text_color=_color_2(_rsi_final_1, 50),              bgcolor=_color_1(_rsi_final_1, 50))
if _rsi_show == true and _tf_3 == true
    table.cell(_dash, 7, 3, str.tostring(math.round(_rsi_final_3)),                     text_color=_color_2(_rsi_final_3, 50),              bgcolor=_color_1(_rsi_final_3, 50))
if _rsi_show == true and _tf_5 == true
    table.cell(_dash, 7, 4, str.tostring(math.round(_rsi_final_5)),                     text_color=_color_2(_rsi_final_5, 50),              bgcolor=_color_1(_rsi_final_5, 50))
if _rsi_show == true and _tf_15 == true
    table.cell(_dash, 7, 5, str.tostring(math.round(_rsi_final_15)),                    text_color=_color_2(_rsi_final_15, 50),             bgcolor=_color_1(_rsi_final_15, 50))
if _rsi_show == true and _tf_60 == true
    table.cell(_dash, 7, 6, str.tostring(math.round(_rsi_final_60)),                    text_color=_color_2(_rsi_final_60, 50),             bgcolor=_color_1(_rsi_final_60, 50))
    
if _s_rsi_show == true and _tf_1 == true
    table.cell(_dash, 8, 2, str.tostring(math.round(_sto_RSI_k_1)),                     text_color=_color_4(_sto_RSI_k_1, 80, 20),          bgcolor=_color_3(_sto_RSI_k_1, 80, 20))
if _s_rsi_show == true and _tf_3 == true
    table.cell(_dash, 8, 3, str.tostring(math.round(_sto_RSI_k_3)),                     text_color=_color_4(_sto_RSI_k_3, 80, 20),          bgcolor=_color_3(_sto_RSI_k_3, 80, 20))
if _s_rsi_show == true and _tf_5 == true
    table.cell(_dash, 8, 4, str.tostring(math.round(_sto_RSI_k_5)),                     text_color=_color_4(_sto_RSI_k_5, 80, 20),          bgcolor=_color_3(_sto_RSI_k_5, 80, 20))
if _s_rsi_show == true and _tf_15 == true
    table.cell(_dash, 8, 5, str.tostring(math.round(_sto_RSI_k_15)),                    text_color=_color_4(_sto_RSI_k_15, 80, 20),         bgcolor=_color_3(_sto_RSI_k_15, 80, 20))
if _s_rsi_show == true and _tf_60 == true
    table.cell(_dash, 8, 6, str.tostring(math.round(_sto_RSI_k_60)),                    text_color=_color_4(_sto_RSI_k_60, 80, 20),         bgcolor=_color_3(_sto_RSI_k_60, 80, 20))
    
if _s_rsi_show == true and _tf_1 == true
    table.cell(_dash, 9, 2, str.tostring(math.round(_sto_RSI_d_1)),                     text_color=_color_4(_sto_RSI_d_1, 80, 20),          bgcolor=_color_3(_sto_RSI_d_1, 80, 20))
if _s_rsi_show == true and _tf_3 == true
    table.cell(_dash, 9, 3, str.tostring(math.round(_sto_RSI_d_3)),                     text_color=_color_4(_sto_RSI_d_3, 80, 20),          bgcolor=_color_3(_sto_RSI_d_3, 80, 20))
if _s_rsi_show == true and _tf_5 == true
    table.cell(_dash, 9, 4, str.tostring(math.round(_sto_RSI_d_5)),                     text_color=_color_4(_sto_RSI_d_5, 80, 20),          bgcolor=_color_3(_sto_RSI_d_5, 80, 20))
if _s_rsi_show == true and _tf_15 == true
    table.cell(_dash, 9, 5, str.tostring(math.round(_sto_RSI_d_15)),                    text_color=_color_4(_sto_RSI_d_15, 80, 20),         bgcolor=_color_3(_sto_RSI_d_15, 80, 20))
if _s_rsi_show == true and _tf_60 == true
    table.cell(_dash, 9, 6, str.tostring(math.round(_sto_RSI_d_60)),                    text_color=_color_4(_sto_RSI_d_60, 80, 20),         bgcolor=_color_3(_sto_RSI_d_60, 80, 20))
    
if _vwap_show == true and _tf_1 == true
    table.cell(_dash, 10, 2, str.tostring(_trunc(close-_vwap_final_1, _dec)),           text_color=_color_2(close, _vwap_final_1),          bgcolor=_color_1(close, _vwap_final_1))
if _vwap_show == true and _tf_3 == true
    table.cell(_dash, 10, 3, str.tostring(_trunc(close-_vwap_final_3, _dec)),           text_color=_color_2(close, _vwap_final_3),          bgcolor=_color_1(close, _vwap_final_3))
if _vwap_show == true and _tf_5 == true
    table.cell(_dash, 10, 4, str.tostring(_trunc(close-_vwap_final_5, _dec)),           text_color=_color_2(close, _vwap_final_5),          bgcolor=_color_1(close, _vwap_final_5))
if _vwap_show == true and _tf_15 == true
    table.cell(_dash, 10, 5, str.tostring(_trunc(close-_vwap_final_15, _dec)),          text_color=_color_2(close, _vwap_final_15),         bgcolor=_color_1(close, _vwap_final_15))
if _vwap_show == true and _tf_60 == true
    table.cell(_dash, 10, 6, str.tostring(_trunc(close-_vwap_final_60, _dec)),          text_color=_color_2(close, _vwap_final_60),         bgcolor=_color_1(close, _vwap_final_60))

if _tsi_show == true and _tf_1 == true
    table.cell(_dash, 11, 2, str.tostring(_trunc(_tsi_val_1, 2)),                       text_color=_color_2(_tsi_val_1, _tsi_val_1_signal),    bgcolor=_color_1(_tsi_val_1, _tsi_val_1_signal))
    table.cell(_dash, 12, 2, str.tostring(_trunc(_tsi_val_1_signal, 2)),                text_color=_color_2(_tsi_val_1, _tsi_val_1_signal),    bgcolor=_color_1(_tsi_val_1, _tsi_val_1_signal))
    table.cell(_dash, 13, 2, str.tostring(math.round(_tsi_val_1_signal_delta)),         text_color=_color_2(_tsi_val_1_signal_delta, 0),       bgcolor=_color_1(_tsi_val_1_signal_delta, 0))
    
if _tsi_show == true and _tf_3 == true
    table.cell(_dash, 11, 3, str.tostring(_trunc(_tsi_val_3, 2)),                       text_color=_color_2(_tsi_val_3, _tsi_val_3_signal),    bgcolor=_color_1(_tsi_val_3, _tsi_val_3_signal))
    table.cell(_dash, 12, 3, str.tostring(_trunc(_tsi_val_3_signal, 2)),                text_color=_color_2(_tsi_val_3, _tsi_val_3_signal),    bgcolor=_color_1(_tsi_val_3, _tsi_val_3_signal))
    table.cell(_dash, 13, 3, str.tostring(math.round(_tsi_val_3_signal_delta)),         text_color=_color_2(_tsi_val_3_signal_delta, 0),       bgcolor=_color_1(_tsi_val_3_signal_delta, 0))
    
if _tsi_show == true and _tf_5 == true
    table.cell(_dash, 11, 4, str.tostring(_trunc(_tsi_val_5, 2)),                       text_color=_color_2(_tsi_val_5, _tsi_val_5_signal),    bgcolor=_color_1(_tsi_val_5, _tsi_val_5_signal))
    table.cell(_dash, 12, 4, str.tostring(_trunc(_tsi_val_5_signal, 2)),                text_color=_color_2(_tsi_val_5, _tsi_val_5_signal),    bgcolor=_color_1(_tsi_val_5, _tsi_val_5_signal))
    table.cell(_dash, 13, 4, str.tostring(math.round(_tsi_val_5_signal_delta)),     text_color=_color_2(_tsi_val_5_signal_delta, 0),       bgcolor=_color_1(_tsi_val_5_signal_delta, 0))
    
if _tsi_show == true and _tf_15 == true
    table.cell(_dash, 11, 5, str.tostring(_trunc(_tsi_val_15, 2)),                      text_color=_color_2(_tsi_val_15, _tsi_val_15_signal),  bgcolor=_color_1(_tsi_val_15, _tsi_val_15_signal))
    table.cell(_dash, 12, 5, str.tostring(_trunc(_tsi_val_15_signal, 2)),               text_color=_color_2(_tsi_val_15, _tsi_val_15_signal),  bgcolor=_color_1(_tsi_val_15, _tsi_val_15_signal))
    table.cell(_dash, 13, 5, str.tostring(math.round(_tsi_val_15_signal_delta)),        text_color=_color_2(_tsi_val_15_signal_delta, 0),      bgcolor=_color_1(_tsi_val_15_signal_delta, 0))
    
if _tsi_show == true and _tf_60 == true
    table.cell(_dash, 11, 6, str.tostring(_trunc(_tsi_val_60, 2)),                      text_color=_color_2(_tsi_val_60, _tsi_val_60_signal),  bgcolor=_color_1(_tsi_val_60, _tsi_val_60_signal))
    table.cell(_dash, 12, 6, str.tostring(_trunc(_tsi_val_60_signal, 2)),               text_color=_color_2(_tsi_val_60, _tsi_val_60_signal),  bgcolor=_color_1(_tsi_val_60, _tsi_val_60_signal))
    table.cell(_dash, 13, 6, str.tostring(math.round(_tsi_val_60_signal_delta)),        text_color=_color_2(_tsi_val_60_signal_delta, 0),      bgcolor=_color_1(_tsi_val_60_signal_delta, 0))
