Futures All List / Sell Signal
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © gokhanpirnal

//@version=5
indicator("Futures All List / Sell Signal", shorttitle = "Sell Signal",  overlay = false)

// |                                   INPUT                                    |
// Sorting
sortTable = input.string(title="Sort Table by" , defval="High-Low [0]", 
     options=[ "Alphabet", "High-Low [0]", "Low-High [0]"])

// Set Type
set       = input.string(title="Sector Set Type" , defval="1.LIST", 
     options = ["1.LIST", "2.LIST", "3.LIST", "4.LIST", "5.LIST"])

// Table Position
in_table_pos = input.string(title="Table Location", defval= "Top Left", 
     options = [ "Top Right" , "Middle Right" , "Bottom Right" , 
                 "Top Center", "Middle Center", "Bottom Center", 
                 "Top Left"  , "Middle Left"  , "Bottom Left" ], 
              group= "Table Styling")

// Table Size
in_table_size = input.string(title="Table Size", defval="Small", 
     options=["Auto",  "Huge",  "Large", "Normal", "Small", "Tiny"], 
     group= "Table Styling")

// Table Colors
cell_lowColor  = input.color(color.red, title= "Low Cell", 
                     inline="1", group="TableColor")
cell_midColor  = input.color(color.yellow, title= "Mid Cell", 
                     inline="2", group="TableColor")
cell_highColor = input.color(color.green, title= "High Cell", 
                     inline="3", group="TableColor")

background_col = input.color(color.gray, title= "Background Color", 
                     inline="1", group="TableColor")
title_textCol  = input.color(color.white, title="Title Text Color", 
                     inline="2", group="TableColor")
cell_textCol   = input.color(color.black, title="Cell Text Color", 
                     inline="3", group="TableColor")

// |                                  SYMBOLS                                   |
sym_short(s) => 
    str.substring(s, str.pos(s, ":") + 1)

symbol(num, req) =>
    if req == "symbols"
        if  set == "1.LIST"
            symbols = num == 0   ? "BINANCE:1000FLOKIUSDT.P": 
                      num == 1   ? "BINANCE:1000LUNCUSDT.P" :
                      num == 2   ? "BINANCE:1000PEPEUSDT.P" :
                      num == 3   ? "BINANCE:1000SHIBUSDT.P" :
                      num == 4   ? "BINANCE:1000XECUSDT.P"  : 
                      num == 5   ? "BINANCE:1INCHUSDT.P"    :
                      num == 6   ? "BINANCE:AAVEUSDT.P"     : 
                      num == 7   ? "BINANCE:ACHUSDT.P"      :
                      num == 8   ? "BINANCE:ADAUSDT.P"      : 
                      num == 9   ? "BINANCE:AGIXUSDT.P"     :
                      num == 10  ? "BINANCE:ALGOUSDT.P"     : 
                      num == 11  ? "BINANCE:ALICEUSDT.P"    :
                      num == 12  ? "BINANCE:ALPHAUSDT.P"    : 
                      num == 13  ? "BINANCE:AMBUSDT.P"      :
                      num == 14  ? "BINANCE:ANKRUSDT.P"     :
                      num == 15  ? "BINANCE:ANTUSDT.P"      : 
                      num == 16  ? "BINANCE:APEUSDT.P"      :
                      num == 17  ? "BINANCE:API3USDT.P"     : 
                      num == 18  ? "BINANCE:APTUSDT.P"      :
                      num == 19  ? "BINANCE:ARBUSDT.P"      :
                      num == 20  ? "BINANCE:ARPAUSDT.P"     : 
                      num == 21  ? "BINANCE:ARUSDT.P"       :
                      num == 22  ? "BINANCE:ASTRUSDT.P"     : 
                      num == 23  ? "BINANCE:ATAUSDT.P"      :
                      num == 24  ? "BINANCE:ATOMUSDT.P"     : 
                      num == 25  ? "BINANCE:AUDIOUSDT.P"    :
                      num == 26  ? "BINANCE:AVAXUSDT.P"     : 
                      num == 27  ? "BINANCE:AXSUSDT.P"      :
                      num == 28  ? "BINANCE:BAKEUSDT.P"     : 
                      num == 29  ? "BINANCE:BALUSDT.P"      :
                      num == 30  ? "BINANCE:BANDUSDT.P"     : 
                      num == 31  ? "BINANCE:BATUSDT.P"      :
                      num == 32  ? "BINANCE:BCHUSDT.P"      : 
                      num == 33  ? "BINANCE:BELUSDT.P"      :
                      num == 34  ? "BINANCE:BLUEBIRDUSDT.P" : 
                      num == 35  ? "BINANCE:BLURUSDT.P"     : 
                      num == 36  ? "BINANCE:BLZUSDT.P"      :
                      num == 37  ? "BINANCE:BNBUSDT.P"      : 
                      num == 38  ? "BINANCE:BNXUSDT.P"      :
                      num == 39  ? "BINANCE:BTCDOMUSDT.P"   :
                      na
        else if set == "2.LIST"
            symbols = num == 0   ? "BINANCE:BTCUSDT.P"      :
                      num == 1   ? "BINANCE:C98USDT.P"      : 
                      num == 2   ? "BINANCE:CELOUSDT.P"     :
                      num == 3   ? "BINANCE:CELRUSDT.P"     : 
                      num == 4   ? "BINANCE:CFXUSDT.P"      :
                      num == 5   ? "BINANCE:CHRUSDT.P"      : 
                      num == 6   ? "BINANCE:CHZUSDT.P"      :
                      num == 7   ? "BINANCE:CKBUSDT.P"      : 
                      num == 8   ? "BINANCE:COMPUSDT.P"     : 
                      num == 9   ? "BINANCE:COTIUSDT.P"     :
                      num == 10  ? "BINANCE:CRVUSDT.P"      : 
                      num == 11  ? "BINANCE:CTKUSDT.P"      :
                      num == 12  ? "BINANCE:CTSIUSDT.P"     : 
                      num == 13  ? "BINANCE:CVXUSDT.P"      :
                      num == 14  ? "BINANCE:DARUSDT.P"      : 
                      num == 15  ? "BINANCE:DASHUSDT.P"     :
                      num == 16  ? "BINANCE:DEFIUSDT.P"     : 
                      num == 17  ? "BINANCE:DENTUSDT.P"     :
                      num == 18  ? "BINANCE:DGBUSDT.P"      : 
                      num == 19  ? "BINANCE:DOGEUSDT.P"     :
                      num == 20  ? "BINANCE:DOTUSDT.P"      : 
                      num == 21  ? "BINANCE:DUSKUSDT.P"     :
                      num == 22  ? "BINANCE:DYDXUSDT.P"     : 
                      num == 23  ? "BINANCE:EDUUSDT.P"      :
                      num == 24  ? "BINANCE:EGLDUSDT.P"     :
                      num == 25  ? "BINANCE:ENJUSDT.P"      : 
                      num == 26  ? "BINANCE:ENSUSDT.P"      :
                      num == 27  ? "BINANCE:EOSUSDT.P"      : 
                      num == 28  ? "BINANCE:ETCUSDT.P"      :
                      num == 29  ? "BINANCE:ETHUSDT.P"      : 
                      num == 30  ? "BINANCE:FETUSDT.P"      :
                      num == 31  ? "BINANCE:FILUSDT.P"      : 
                      num == 32  ? "BINANCE:FLMUSDT.P"      :
                      num == 33  ? "BINANCE:FLOWUSDT.P"     : 
                      num == 34  ? "BINANCE:FOOTBALLUSDT.P" :
                      num == 35  ? "BINANCE:FTMUSDT.P"      : 
                      num == 36  ? "BINANCE:FXSUSDT.P"      :
                      num == 37  ? "BINANCE:GALAUSDT.P"     : 
                      num == 38  ? "BINANCE:GALUSDT.P"      :
                      num == 39  ? "BINANCE:GMTUSDT.P"      :
                      na
        else if set == "3.LIST"
            symbols = num == 0   ? "BINANCE:GMXUSDT.P"      :
                      num == 1   ? "BINANCE:GRTUSDT.P"      : 
                      num == 2   ? "BINANCE:GTCUSDT.P"      : 
                      num == 3   ? "BINANCE:HBARUSDT.P"     : 
                      num == 4   ? "BINANCE:HFTUSDT.P"      :
                      num == 5   ? "BINANCE:HIGHUSDT.P"     : 
                      num == 6   ? "BINANCE:HOOKUSDT.P"     : 
                      num == 7   ? "BINANCE:HOTUSDT.P"      : 
                      num == 8   ? "BINANCE:ICPUSDT.P"      : 
                      num == 9   ? "BINANCE:ICXUSDT.P"      : 
                      num == 10  ? "BINANCE:IDEXUSDT.P"     :
                      num == 11  ? "BINANCE:IDUSDT.P"       :
                      num == 12  ? "BINANCE:IMXUSDT.P"      : 
                      num == 13  ? "BINANCE:INJUSDT.P"      : 
                      num == 14  ? "BINANCE:IOSTUSDT.P"     :
                      num == 15  ? "BINANCE:IOTAUSDT.P"     : 
                      num == 16  ? "BINANCE:IOTXUSDT.P"     :  
                      num == 17  ? "BINANCE:JASMYUSDT.P"    :
                      num == 18  ? "BINANCE:JOEUSDT.P"      : 
                      num == 19  ? "BINANCE:KAVAUSDTPERP"   :
                      num == 20  ? "BINANCE:KEYUSDT.P"      :
                      num == 21  ? "BINANCE:KLAYUSDT.P"     :
                      num == 22  ? "BINANCE:KNCUSDT.P"      : 
                      num == 23  ? "BINANCE:KSMUSDT.P"      : 
                      num == 24  ? "BINANCE:LDOUSDT.P"      :
                      num == 25  ? "BINANCE:LEVERUSDT.P"    : 
                      num == 26  ? "BINANCE:LINAUSDT.P"     : 
                      num == 27  ? "BINANCE:LINKUSDT.P"     : 
                      num == 28  ? "BINANCE:LITUSDT.P"      : 
                      num == 29  ? "BINANCE:LPTUSDT.P"      : 
                      num == 30  ? "BINANCE:LQTYUSDT.P"     : 
                      num == 31  ? "BINANCE:LRCUSDT.P"      :
                      num == 32  ? "BINANCE:LTCUSDT.P"      : 
                      num == 33  ? "BINANCE:LUNA2USDT.P"    :
                      num == 34  ? "BINANCE:MAGICUSDT.P"    : 
                      num == 35  ? "BINANCE:MANAUSDT.P"     :
                      num == 36  ? "BINANCE:MASKUSDT.P"     : 
                      num == 37  ? "BINANCE:MATICUSDT.P"    :
                      num == 38  ? "BINANCE:MINAUSDT.P"     : 
                      num == 39  ? "BINANCE:MKRUSDT.P"      :
                      na
        else if set == "4.LIST"
            symbols = num == 0   ? "BINANCE:MTLUSDT.P"      : 
                      num == 1   ? "BINANCE:NEARUSDT.P"     :
                      num == 2   ? "BINANCE:NEOUSDT.P"      : 
                      num == 3   ? "BINANCE:NKNUSDT.P"      :
                      num == 4   ? "BINANCE:OCEANUSDT.P"    : 
                      num == 5   ? "BINANCE:OGNUSDT.P"      :
                      num == 6   ? "BINANCE:OMGUSDT.P"      : 
                      num == 7   ? "BINANCE:ONEUSDT.P"      :
                      num == 8   ? "BINANCE:ONTUSDT.P"      : 
                      num == 9   ? "BINANCE:OPUSDT.P"       :
                      num == 10  ? "BINANCE:PEOPLEUSDT.P"   : 
                      num == 11  ? "BINANCE:PERPUSDT.P"     :
                      num == 12  ? "BINANCE:PHBUSDT.P"      : 
                      num == 13  ? "BINANCE:QNTUSDT.P"      :
                      num == 14  ? "BINANCE:QTUMUSDT.P"     :
                      num == 15  ? "BINANCE:RADUSDT.P"      : 
                      num == 16  ? "BINANCE:RDNTUSDT.P"     :  
                      num == 17  ? "BINANCE:REEFUSDT.P"     : 
                      num == 18  ? "BINANCE:RENUSDT.P"      : 
                      num == 19  ? "BINANCE:RLCUSDT.P"      :
                      num == 20  ? "BINANCE:RNDRUSDT.P"     : 
                      num == 21  ? "BINANCE:ROSEUSDT.P"     : 
                      num == 22  ? "BINANCE:RSRUSDT.P"      : 
                      num == 23  ? "BINANCE:RUNEUSDT.P"     : 
                      num == 24  ? "BINANCE:RVNUSDT.P"      : 
                      num == 25  ? "BINANCE:SANDUSDT.P"     : 
                      num == 26  ? "BINANCE:SFPUSDT.P"      : 
                      num == 27  ? "BINANCE:SKLUSDT.P"      : 
                      num == 28  ? "BINANCE:SNXUSDT.P"      : 
                      num == 29  ? "BINANCE:SOLUSDT.P"      : 
                      num == 30  ? "BINANCE:SPELLUSDT.P"    : 
                      num == 31  ? "BINANCE:SSVUSDT.P"      : 
                      num == 32  ? "BINANCE:STGUSDT.P"      : 
                      num == 33  ? "BINANCE:STMXUSDT.P"     : 
                      num == 34  ? "BINANCE:STORJUSDT.P"    : 
                      num == 35  ? "BINANCE:STXUSDT.P"      :
                      num == 36  ? "BINANCE:SUIUSDT.P"      :
                      num == 37  ? "BINANCE:SUSHIUSDT.P"    : 
                      num == 38  ? "BINANCE:SXPUSDT.P"      :
                      num == 39  ? "BINANCE:THETAUSDT.P"    :
                      na
        else if set == "5.LIST"
            symbols = num == 0   ? "BINANCE:TLMUSDT.P"      : 
                      num == 1   ? "BINANCE:TOMOUSDT.P"     :
                      num == 2   ? "BINANCE:TRBUSDT.P"      : 
                      num == 3   ? "BINANCE:TRUUSDT.P"      :
                      num == 4   ? "BINANCE:TRXUSDT.P"      :
                      num == 5   ? "BINANCE:TUSDT.P"        : 
                      num == 6   ? "BINANCE:UMAUSDT.P"      :
                      num == 7   ? "BINANCE:UNFIUSDT.P"     : 
                      num == 8   ? "BINANCE:UNIUSDT.P"      : 
                      num == 9   ? "BINANCE:USDCUSDT.P"     :
                      num == 10  ? "BINANCE:VETUSDT.P"      : 
                      num == 11  ? "BINANCE:WAVESUSDT.P"    :
                      num == 12  ? "BINANCE:WOOUSDT.P"      : 
                      num == 13  ? "BINANCE:XEMUSDT.P"      :
                      num == 14  ? "BINANCE:XLMUSDT.P"      : 
                      num == 15  ? "BINANCE:XMRUSDT.P"      :
                      num == 16  ? "BINANCE:XRPUSDT.P"      : 
                      num == 17  ? "BINANCE:XTZUSDT.P"      : 
                      num == 18  ? "BINANCE:XVSUSDT.P"      :
                      num == 19  ? "BINANCE:YFIUSDT.P"      :
                      num == 20  ? "BINANCE:ZECUSDT.P"      : 
                      num == 21  ? "BINANCE:ZENUSDT.P"      : 
                      num == 22  ? "BINANCE:ZILUSDT.P"      : 
                      num == 23  ? "BINANCE:ZRXUSDT.P"      :
                      num == 24  ? "BINANCE:BTCUSDT.P"      : 
                      num == 25  ? "BINANCE:BTCDOMUSDT.P"   :
                      na

// |                                 CALCULATION                                |
//Order
[colMtx, order] = switch sortTable
    "High-Low [0]" => [1, order.descending]
    "Low-High [0]" => [1, order.ascending ]
    => [0, order.ascending]

// Matrix 
sectors = matrix.new<float>(40, 2, na)

symbol01 = syminfo.tickerid


long = input(title='TSI Long Length', defval=3)
short = input(title='TSI Short Length', defval=3)
signal = input(title='TSI Signal Length', defval=6)
len = input.int(6, minval=1, title='RSI Length')
priceopen = open
double_smoothopen(srcopen, long, short) =>
    fist_smoothopen = ta.ema(srcopen, long)
    ta.ema(fist_smoothopen, short)
pcopen = ta.change(priceopen)
double_smoothed_pcopen = double_smoothopen(pcopen, long, short)
double_smoothed_abs_pcopen = double_smoothopen(math.abs(pcopen), long, short)
tsi_valueopen = 100 * (double_smoothed_pcopen / double_smoothed_abs_pcopen)

srcopen = input(open, 'Source')
upopen = ta.rma(math.max(ta.change(srcopen), 0), len)
downopen = ta.rma(-math.min(ta.change(srcopen), 0), len)
rsiopen = downopen == 0 ? 100 : upopen == 0 ? 0 : 100 - 100 / (1 + upopen / downopen)

totalopen = tsi_valueopen + ta.ema(tsi_valueopen, signal) + rsiopen


pricehigh = high
double_smoothhigh(srchigh, long, short) =>
    fist_smoothhigh = ta.ema(srchigh, long)
    ta.ema(fist_smoothhigh, short)
pchigh = ta.change(pricehigh)
double_smoothed_pchigh = double_smoothhigh(pchigh, long, short)
double_smoothed_abs_pchigh = double_smoothhigh(math.abs(pchigh), long, short)
tsi_valuehigh = 100 * (double_smoothed_pchigh / double_smoothed_abs_pchigh)

srchigh = input(high, 'Source')
uphigh = ta.rma(math.max(ta.change(srchigh), 0), len)
downhigh = ta.rma(-math.min(ta.change(srchigh), 0), len)
rsihigh = downhigh == 0 ? 100 : uphigh == 0 ? 0 : 100 - 100 / (1 + uphigh / downhigh)

totalhigh = tsi_valuehigh + ta.ema(tsi_valuehigh, signal) + rsihigh


pricelow = low
double_smoothlow(srclow, long, short) =>
    fist_smoothlow = ta.ema(srclow, long)
    ta.ema(fist_smoothlow, short)
pclow = ta.change(pricelow)
double_smoothed_pclow = double_smoothlow(pclow, long, short)
double_smoothed_abs_pclow = double_smoothlow(math.abs(pclow), long, short)
tsi_valuelow = 100 * (double_smoothed_pclow / double_smoothed_abs_pclow)

srclow = input(low, 'Source')
uplow = ta.rma(math.max(ta.change(srclow), 0), len)
downlow = ta.rma(-math.min(ta.change(srclow), 0), len)
rsilow = downlow == 0 ? 100 : uplow == 0 ? 0 : 100 - 100 / (1 + uplow / downlow)

totallow = tsi_valuelow + ta.ema(tsi_valuelow, signal) + rsilow


priceclose = close
double_smoothclose(srcclose, long, short) =>
    fist_smoothclose = ta.ema(srcclose, long)
    ta.ema(fist_smoothclose, short)
pcclose = ta.change(priceclose)
double_smoothed_pcclose = double_smoothclose(pcclose, long, short)
double_smoothed_abs_pcclose = double_smoothclose(math.abs(pcclose), long, short)
tsi_valueclose = 100 * (double_smoothed_pcclose / double_smoothed_abs_pcclose)

srcclose = input(close, 'Source')
upclose = ta.rma(math.max(ta.change(srcclose), 0), len)
downclose = ta.rma(-math.min(ta.change(srcclose), 0), len)
rsiclose = downclose == 0 ? 100 : upclose == 0 ? 0 : 100 - 100 / (1 + upclose / downclose)

totalclose = (tsi_valueclose + ta.ema(tsi_valueclose, signal) + rsiclose)

a = array.from(totalopen, totalhigh, totallow, totalclose)
maksdata = array.max(a, 0) // 1
dump=maksdata[0]+totalclose[0]
plot(dump,title="Dump",color=color.rgb(255,0,255,0),linewidth=2)

hline(600, title='Üst Sınır', color=#00ff00)
hline(0,title="Zero", color=#00ffff)
hline(-400, title='Alt Sınır', color=#ff0000)

// Fill Matrix Function
fun_matrix(mtxName, row, adj) =>
    
    // Symbol Name
    string sym= symbol(row, "symbols")
    s = ticker.modify(sym, syminfo.session)
    
    // Symbol code
    matrix.set(mtxName, row + adj, 0, row)
    
    // Dump
    rt0 = request.security(s, timeframe.period, dump[0])
    matrix.set(mtxName, row + adj, 1, rt0)

//++++++++++ Sector Matrix
fun_matrix(sectors,  0, 0)
fun_matrix(sectors,  1, 0)
fun_matrix(sectors,  2, 0)
fun_matrix(sectors,  3, 0)
fun_matrix(sectors,  4, 0)
fun_matrix(sectors,  5, 0)
fun_matrix(sectors,  6, 0)
fun_matrix(sectors,  7, 0)
fun_matrix(sectors,  8, 0)
fun_matrix(sectors,  9, 0)
fun_matrix(sectors,  10, 0)
fun_matrix(sectors,  11, 0)
fun_matrix(sectors,  12, 0)
fun_matrix(sectors,  13, 0)
fun_matrix(sectors,  14, 0)
fun_matrix(sectors,  15, 0)
fun_matrix(sectors,  16, 0)
fun_matrix(sectors,  17, 0)
fun_matrix(sectors,  18, 0)
fun_matrix(sectors,  19, 0)
fun_matrix(sectors,  20, 0)
fun_matrix(sectors,  21, 0)
fun_matrix(sectors,  22, 0)
fun_matrix(sectors,  23, 0)
fun_matrix(sectors,  24, 0)
fun_matrix(sectors,  25, 0)
fun_matrix(sectors,  26, 0)
fun_matrix(sectors,  27, 0)
fun_matrix(sectors,  28, 0)
fun_matrix(sectors,  29, 0)
fun_matrix(sectors,  30, 0)
fun_matrix(sectors,  31, 0)
fun_matrix(sectors,  32, 0)
fun_matrix(sectors,  33, 0)
fun_matrix(sectors,  34, 0)
fun_matrix(sectors,  35, 0)
fun_matrix(sectors,  36, 0)
fun_matrix(sectors,  37, 0)
fun_matrix(sectors,  38, 0)
fun_matrix(sectors,  39, 0)

matrix.sort(sectors, colMtx, order)

// |                                   Table                                    |
// Get Table Position
table_pos(p) => 
    switch p
        "Top Right"     => position.top_right     
        "Middle Right"  => position.middle_right   
        "Bottom Right"  => position.bottom_right  
        "Top Center"    => position.top_center    
        "Middle Center" => position.middle_center
        "Bottom Center" => position.bottom_center
        "Top Left"      => position.top_left      
        "Middle Left"   => position.middle_left 
        => position.bottom_left

// Get Table Size
table_size(s) =>
    switch s
        "Auto"   => size.auto   
        "Huge"   => size.huge   
        "Large"  => size.large  
        "Normal" => size.normal 
        "Small"  => size.small
        => size.tiny
tz = table_size(in_table_size)

// Get Title Column
fun_titlCol(tbl, col, txtCol) =>
    table.cell(tbl, col, 0, text_halign =text.align_left, 
     text       = txtCol, 
     text_color = title_textCol, 
     text_size  = tz, 
     bgcolor    = background_col)
   
// Get Cell Values
fun_cell(tbl, row, mtxName, mtxRow) =>

    loSh = matrix.get(mtxName, mtxRow, 1)
    bglSColor    = ( loSh<0 ? color.rgb(255,106,106,0):color.rgb(106,255,106,0))

    table.cell(tbl, 0, row, text_halign=text.align_right, text_valign=text.align_center,
     text       = sym_short(symbol(matrix.get(mtxName, mtxRow, 0), "symbols")),
     text_color = title_textCol, text_size = tz, bgcolor= background_col)
        
    table.cell(tbl, 1, row, text_halign=text.align_right, text_valign=text.align_center,
     text       = str.tostring(matrix.get(mtxName,mtxRow,1),"###.####"),
     text_color = cell_textCol, text_size = tz, bgcolor = bglSColor)
        
// Create Table
var tbl = table.new(table_pos(in_table_pos), 2, 41, frame_width = 5, 
         border_width = 1, border_color = color.new(title_textCol, 100))

// Fill up Cells.
if barstate.islast
    table.clear(tbl, 0, 0, 1, 40)
    
    // columns
    fun_titlCol(tbl, 0, "---SYMBOL---")
    fun_titlCol(tbl, 1, "DUMP \nPoint=+600")

    for i = 1 to 40
        fun_cell(tbl, i, sectors, i - 1)
        