Multi-Timeframe 10X
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Beardy_Fred

//@version=5
indicator(title="MTF 10X", overlay = true)

//INPUTS
len             = input.int(14, "Directional Length")
ADX_T           = input.int(20, "ADX Length")

//DMI CALCULATIONS - Tradingview Built-In DMI Indicator
up              = ta.change(high)
down            = -ta.change(low)
plusDM          = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM         = na(down) ? na : (down > up and down > 0 ? down : 0)
trur            = ta.rma(ta.tr, len)
plus            = fixnan(100 * ta.rma(plusDM, len) / trur)
minus           = fixnan(100 * ta.rma(minusDM, len) / trur)
sum             = plus + minus
adx             = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), len)

//10X CALCULATIONS
D_Up            = (plus > minus) and (adx > ADX_T)
D_Down          = (minus > plus) and (adx > ADX_T)
Neutral         = (adx < ADX_T)

D_Up_Color      = input.color(color.new(color.green, 0), title = "Uptrend")
D_Down_Color    = input.color(color.new(color.red, 0), title = "Downtrend")
Neutral_Color   = input.color(color.new(color.yellow, 0), title = "Neutral")

MTF10_Color     = Neutral ? Neutral_Color : D_Up ? D_Up_Color : D_Down ? D_Down_Color : na

//MULTI TIMEFRAME SQUEEZE COLOR
[MTF10_1m]      = request.security(syminfo.tickerid, "1", [MTF10_Color])
[MTF10_5m]      = request.security(syminfo.tickerid, "5", [MTF10_Color])
[MTF10_15m]     = request.security(syminfo.tickerid, "15", [MTF10_Color])
[MTF10_30m]     = request.security(syminfo.tickerid, "30", [MTF10_Color])
[MTF10_1H]      = request.security(syminfo.tickerid, "60", [MTF10_Color])
[MTF10_4H]      = request.security(syminfo.tickerid, "240", [MTF10_Color])
[MTF10_D]       = request.security(syminfo.tickerid, "D", [MTF10_Color])
[MTF10_W]       = request.security(syminfo.tickerid, "W", [MTF10_Color])
[MTF10_M]       = request.security(syminfo.tickerid, "M", [MTF10_Color])

tableYposInput  = input.string("top", "Panel position", options = ["top", "middle", "bottom"])
tableXposInput  = input.string("right", "", options = ["left", "center", "right"])

var table TTM   = table.new(tableYposInput + "_" + tableXposInput, 10, 1, border_width = 1)

TC              = input.color(color.new(color.white, 0), "Table Text Color")
TS              = input.string(size.small, "Table Text Size", options = [size.tiny, size.small, size.normal, size.large])

if barstate.isconfirmed
    table.cell(TTM, 0, 0, "10X", text_color = color.new(color.white, 0), bgcolor = color.new(color.gray, 0), text_size = TS)
    table.cell(TTM, 1, 0, "1m", text_color = TC, bgcolor = MTF10_1m, text_size = TS)
    table.cell(TTM, 2, 0, "5m", text_color = TC, bgcolor = MTF10_5m, text_size = TS)
    table.cell(TTM, 3, 0, "15m", text_color = TC, bgcolor = MTF10_15m, text_size = TS)
    table.cell(TTM, 4, 0, "30m", text_color = TC, bgcolor = MTF10_30m, text_size = TS)
    table.cell(TTM, 5, 0, "1H", text_color = TC, bgcolor = MTF10_1H, text_size = TS)
    table.cell(TTM, 6, 0, "4H", text_color = TC, bgcolor = MTF10_4H, text_size = TS)
    table.cell(TTM, 7, 0, "D", text_color = TC, bgcolor = MTF10_D, text_size = TS)
    table.cell(TTM, 8, 0, "W", text_color = TC, bgcolor = MTF10_W, text_size = TS)
    table.cell(TTM, 9, 0, "M", text_color = TC, bgcolor = MTF10_M, text_size = TS)
