Traders Trend Dashboard
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AlexFuch

//@version=5

indicator("Traders Trend Dashboard", shorttitle = "TTD", overlay = true, scale = scale.none, max_lines_count = 500)

dashboard_position  = input.session("Middle Right", "Posision", ["Top Right", "Bottom Right", "Top Left", "Bottom Left", "Top Center", "Bottom Center", "Middle Right"], group = 'Table Settings')
text_size = input.session('Normal', "Size", options = ["Tiny", "Small", "Normal", "Large"], group = 'Table Settings')
text_color = input(#d1d4dc, title = "Text Color", group = 'Table Settings')
table_color = input(color.gray, title = "Border Color", group = 'Table Settings')
uptrend_indicator = input("🟢", title = "Uptrend Indicator", group = 'Table Settings')
downtrend_indicator = input("🔴", title = "Downtrend Indicator", group = 'Table Settings')
neutraltrend_indicator = input("⚫️", title = "Neutral trend Indicator", group = 'Table Settings')
ema_length = input.int(title = "Length", defval = 50, minval = 1, maxval = 800, group = 'EMA Settings')
ema_src = input(close, title="Source", group = 'EMA Settings')
max_table_size = 200
min_table_size = 10

show_1m = input(true, title = 'Show 1m', group = 'Timeframe Settings')
show_3m = input(true, title = 'Show 3m ', group = 'Timeframe Settings')
show_5m = input(true, title = 'Show 5m', group = 'Timeframe Settings')
show_8m = input(false, title = 'Show 8m', group = 'Timeframe Settings')
show_12m = input(false, title = 'Show 12m', group = 'Timeframe Settings')
show_15m = input(true, title = 'Show 15m', group = 'Timeframe Settings')
show_20m = input(false, title = 'Show 20m', group = 'Timeframe Settings')
show_30m = input(false, title = 'Show 30m', group = 'Timeframe Settings')
show_45m = input(false, title = 'Show 45m', group = 'Timeframe Settings')
show_1h = input(true, title = 'Show 1h', group = 'Timeframe Settings')
show_2h = input(false, title = 'Show 2h', group = 'Timeframe Settings')
show_3h = input(false, title = 'Show 3h', group = 'Timeframe Settings')
show_4h = input(true, title = 'Show 4h', group = 'Timeframe Settings')
show_D = input(false, title = 'Show D', group = 'Timeframe Settings')
show_W = input(false, title = 'Show W', group = 'Timeframe Settings')
show_M = input(false, title = 'Show M', group = 'Timeframe Settings')

var table_position = dashboard_position == 'Top Right' ? position.top_right :
  dashboard_position == 'Top Left' ? position.top_left :
  dashboard_position == 'Top Center' ? position.top_center :
  dashboard_position == 'Bottom Right' ? position.bottom_right :
  dashboard_position == 'Bottom Left' ? position.bottom_left :
  dashboard_position == 'Bottom Center' ? position.bottom_center :
  dashboard_position == 'Middle Right' ? position.middle_right :
  dashboard_position == 'Middle Left' ? position.middle_left : position.middle_right
  
var table_text_size = text_size == 'Normal' ? size.normal :
  text_size == 'Large' ? size.large :
  text_size == 'Tiny' ? size.tiny :
  text_size == 'Small' ? size.small : size.normal

var t = table.new(table_position, 15, math.abs(max_table_size - min_table_size) + 2,
  frame_color = table_color,
  frame_width = 2,
  border_color = table_color,
  border_width = 2)

get_candle_values() =>
    current_candle = ta.ema(ema_src, ema_length)
    previous_candle = current_candle[1]
    [current_candle, previous_candle]

get_trend_indicator(current_candle, previous_candle) =>
  current_candle > previous_candle ? uptrend_indicator : current_candle < previous_candle ? downtrend_indicator : neutraltrend_indicator

[current_1m, previous_1m] = request.security(syminfo.tickerid, "1", get_candle_values(), lookahead = barmerge.lookahead_on)
[current_3m, previous_3m] = request.security(syminfo.tickerid, "3", get_candle_values(), lookahead = barmerge.lookahead_on)
[current_5m, previous_5m] = request.security(syminfo.tickerid, "5", get_candle_values(), lookahead = barmerge.lookahead_on)
[current_8m, previous_8m] = request.security(syminfo.tickerid, "8", get_candle_values(), lookahead = barmerge.lookahead_on)
[current_12m, previous_12m] = request.security(syminfo.tickerid, "12", get_candle_values(), lookahead = barmerge.lookahead_on)
[current_15m, previous_15m] = request.security(syminfo.tickerid, "15", get_candle_values(), lookahead = barmerge.lookahead_on)
[current_20m, previous_20m] = request.security(syminfo.tickerid, "20", get_candle_values(), lookahead = barmerge.lookahead_on)
[current_30m, previous_30m] = request.security(syminfo.tickerid, "30", get_candle_values(), lookahead = barmerge.lookahead_on)
[current_45m, previous_45m] = request.security(syminfo.tickerid, "45", get_candle_values(), lookahead = barmerge.lookahead_on)
[current_1h, previous_1h] = request.security(syminfo.tickerid, "60", get_candle_values(), lookahead = barmerge.lookahead_on)
[current_2h, previous_2h] = request.security(syminfo.tickerid, "120", get_candle_values(), lookahead = barmerge.lookahead_on)
[current_3h, previous_3h] = request.security(syminfo.tickerid, "180", get_candle_values(), lookahead = barmerge.lookahead_on)
[current_4h, previous_4h] = request.security(syminfo.tickerid, "240", get_candle_values(), lookahead = barmerge.lookahead_on)
[current_D, previous_D] = request.security(syminfo.tickerid, "D", get_candle_values(), lookahead = barmerge.lookahead_on)
[current_W, previous_W] = request.security(syminfo.tickerid, "W", get_candle_values(), lookahead = barmerge.lookahead_on)
[current_M, previous_M] = request.security(syminfo.tickerid, "M", get_candle_values(), lookahead = barmerge.lookahead_on)
[current_3M, previous_3M] = request.security(syminfo.tickerid, "3M", get_candle_values(), lookahead = barmerge.lookahead_on)
[current_6M, previous_6M] = request.security(syminfo.tickerid, "6M", get_candle_values(), lookahead = barmerge.lookahead_on)
[current_12M, previous_12M] = request.security(syminfo.tickerid, "12M", get_candle_values(), lookahead = barmerge.lookahead_on)

if (barstate.islast)
    if (show_1m)
        table.cell(t, 1, 2, "1m", text_color = text_color, text_size = table_text_size)
        table.cell(t, 5, 2, get_trend_indicator(current_1m, previous_1m), text_color = text_color, text_size = table_text_size)

    if (show_3m)
        table.cell(t, 1, 3, "3m", text_color = text_color, text_size = table_text_size)
        table.cell(t, 5, 3, get_trend_indicator(current_3m, previous_3m), text_color = text_color, text_size = table_text_size)

    if (show_5m)
        table.cell(t, 1, 4, "5m", text_color = text_color, text_size = table_text_size)
        table.cell(t, 5, 4, get_trend_indicator(current_5m, previous_5m), text_color = text_color, text_size = table_text_size)

    if (show_8m)
        table.cell(t, 1, 5, "8m", text_color = text_color, text_size = table_text_size)
        table.cell(t, 5, 5, get_trend_indicator(current_8m, previous_8m), text_color = text_color, text_size = table_text_size)

    if (show_12m)
        table.cell(t, 1, 6, "12m", text_color = text_color, text_size = table_text_size)
        table.cell(t, 5, 6, get_trend_indicator(current_12m, previous_12m), text_color = text_color, text_size = table_text_size)

    if (show_15m)
        table.cell(t, 1, 7, "15m", text_color = text_color, text_size = table_text_size)
        table.cell(t, 5, 7, get_trend_indicator(current_15m, previous_15m), text_color = text_color, text_size = table_text_size)

    if (show_20m)
        table.cell(t, 1, 8, "20m", text_color = text_color, text_size = table_text_size)
        table.cell(t, 5, 8, get_trend_indicator(current_20m, previous_20m), text_color = text_color, text_size = table_text_size)

    if (show_30m)
        table.cell(t, 1, 9, "30m", text_color = text_color, text_size = table_text_size)
        table.cell(t, 5, 9, get_trend_indicator(current_30m, previous_30m), text_color = text_color, text_size = table_text_size)

    if (show_45m)
        table.cell(t, 1, 10, "45m", text_color = text_color, text_size = table_text_size)
        table.cell(t, 5, 10, get_trend_indicator(current_45m, previous_45m), text_color = text_color, text_size = table_text_size)

    if (show_1h)
        table.cell(t, 1, 11, "1h", text_color = text_color, text_size = table_text_size)
        table.cell(t, 5, 11, get_trend_indicator(current_1h, previous_1h), text_color = text_color, text_size = table_text_size)

    if (show_2h)
        table.cell(t, 1, 12, "2h", text_color = text_color, text_size = table_text_size)
        table.cell(t, 5, 12, get_trend_indicator(current_2h, previous_2h), text_color = text_color, text_size = table_text_size)

    if (show_3h)
        table.cell(t, 1, 13, "3h", text_color = text_color, text_size = table_text_size)
        table.cell(t, 5, 13, get_trend_indicator(current_3h, previous_3h), text_color = text_color, text_size = table_text_size)

    if (show_4h)
        table.cell(t, 1, 14, "4h", text_color = text_color, text_size = table_text_size)
        table.cell(t, 5, 14, get_trend_indicator(current_4h, previous_4h), text_color = text_color, text_size = table_text_size)

    if (show_D)
        table.cell(t, 1, 15, "D", text_color = text_color, text_size = table_text_size)
        table.cell(t, 5, 15, get_trend_indicator(current_D, previous_D), text_color = text_color, text_size = table_text_size)

    if (show_W)
        table.cell(t, 1, 16, "W", text_color = text_color, text_size = table_text_size)
        table.cell(t, 5, 16, get_trend_indicator(current_W, previous_W), text_color = text_color, text_size = table_text_size)

    if (show_M)
        table.cell(t, 1, 17, "M", text_color = text_color, text_size = table_text_size)
        table.cell(t, 5, 17, get_trend_indicator(current_M, previous_M), text_color = text_color, text_size = table_text_size)
