RSI Momentum Trend Screener
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TZack88

//@version=5
indicator(title="RSI Momentum Trend Screener", format=format.price, precision=2,overlay = true)
// ** ---> Inputs ------------- {
array<string> names                         = array.new_string(0)
array<bool> USEbool                         = array.new_bool(0)
array<bool> rsi_pos                         = array.new_bool(0)
array<bool> rsi_neg                         = array.new_bool(0)
string RSI_group                            = "RSI Settings"
string mom_group                            = "Momentum Vales"
string table_name                           = 'RSI Momentum Trend Screener'
string table_Group                          = "Table"     
int Len2                                    = input(14,"RSI 1️⃣",inline = "rsi",group = RSI_group)
int pmom                                    = input(65," Positive above",inline = "rsi1",group =RSI_group )
int nmom                                    = input(32,"Negative below",inline = "rsi1",group =RSI_group )
float rsi                                   = ta.rsi(close, Len2)

// Table data 

bool show_table                             = input.bool(true,title= "Show Table ❓",inline = "002",group = table_Group)
string position                             = input.string("Top Right", 
     options = ["Middle Right","Top Center","Top Right","Middle Left","Middle Center","Bottom Left","Bottom Center","Bottom Right"],
     title = 'Position',
     inline = "002",
     group = table_Group
     )
color textcolos                             = input.color(color.rgb(255, 186, 75),title = "Text Color",inline = "002",group = table_Group)

table_position() =>
    switch position
        "Middle Right" => position.middle_right
        "Top Center" => position.top_center
        "Top Right" => position.top_right
        "Middle Left" => position.middle_left
        "Middle Center" => position.middle_center
        "Bottom Left" => position.bottom_left
        "Bottom Center" => position.bottom_center
        "Bottom Right" => position.bottom_right      


var summary_table          = table.new(table_position(), 15, 50, frame_color=color.rgb(241, 124, 8), frame_width=2,border_width = 2)
change_color(con)=>
    con ? color.rgb(6, 104, 57) : color.rgb(153, 7, 7)    
 
table_cell(table,_row,in1,in2,coloz)=>
    text_color = show_table ? color.rgb(210, 210, 210) : color.black
    table.cell(table, 0, _row, in1, text_color=text_color,bgcolor = color.rgb(120, 123, 134, 38))
    table.cell(table, 1, _row, str.tostring(in2), text_color=text_color,bgcolor = change_color(coloz))

table_cell2(table,_row,in1,in2,coloz)=>
    text_color = show_table ? color.rgb(210, 210, 210) : color.black
    table.cell(table, 3, _row, in1, text_color=text_color,bgcolor = color.rgb(120, 123, 134, 38))
    table.cell(table, 4, _row, str.tostring(in2), text_color=text_color,bgcolor = change_color(coloz))    

//------------------- }

// Lets calculate our RSI MOM Trend and return it 
GetData(simple string pair) =>
    var bool positive       = false
    var bool negative       = false
    Pinfo =  rsi[1] < pmom and rsi > pmom and rsi > nmom and ta.change(ta.ema(close,5)) > 0
    Ninfo =  rsi < nmom and ta.change(ta.ema(close,5)) < 0
    [ p_mom ,n_mom ] = request.security(pair,"",[Pinfo,Ninfo])
    if p_mom
        positive:= true
        negative:= false

    if n_mom
        positive:= false
        negative:= true     

    [ positive , negative ] 


// ** ---> Momentums ------------- {

bool T01                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's01')
bool T02                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's02')
bool T03                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's03')
bool T04                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's04')
bool T05                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's05')
bool T06                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's06')
bool T07                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's07')
bool T08                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's08')
bool T09                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's09')
bool T10                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's10')
bool T11                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's11')
bool T12                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's12')
bool T13                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's13')
bool T14                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's14')
bool T15                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's15')
bool T16                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's16')
bool T17                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's17')
bool T18                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's18')
bool T19                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's19')
bool T20                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's20')
bool T21                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's21')
bool T22                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's22')
bool T23                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's23')
bool T24                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's24')
bool T25                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's25')
bool T26                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's26')
bool T27                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's27')
bool T28                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's28')
bool T29                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's29')
bool T30                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's30')
bool T31                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's31')
bool T32                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's32')
bool T33                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's33')
bool T34                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's34')
bool T35                                    = input.bool(true,  title = "",         group = 'Symbols',       inline = 's35')
bool T36                                    = input.bool(true,  title = "",          group = 'Symbols',      inline = 's36')
bool T37                                    = input.bool(true,  title = "",          group = 'Symbols',      inline = 's37')
bool T38                                    = input.bool(true,  title = "",          group = 'Symbols',      inline = 's38')
bool T39                                    = input.bool(true,  title = "",          group = 'Symbols',      inline = 's39')
bool T40                                    = input.bool(true,  title = "",          group = 'Symbols',      inline = 's40')
string s01                                  = input.symbol('XRPUSDT',  group = 'Symbols', inline = 's01',title = "Symbol 1")
string s02                                  = input.symbol('BTCUSDT',  group = 'Symbols', inline = 's02',title = "Symbol 2")
string s03                                  = input.symbol('DOGEUSDT', group = 'Symbols', inline = 's03',title = "Symbol 3")
string s04                                  = input.symbol('BNBUSDT',  group = 'Symbols', inline = 's04',title = "Symbol 4")
string s05                                  = input.symbol('ETHUSDT',  group = 'Symbols', inline = 's05',title = "Symbol 5")
string s06                                  = input.symbol('ADAUSDT',  group = 'Symbols', inline = 's06',title = "Symbol 6")
string s07                                  = input.symbol('XRPBTC',   group = 'Symbols', inline = 's07',title = "Symbol 7")
string s08                                  = input.symbol('DOGEBTC',  group = 'Symbols', inline = 's08',title = "Symbol 8")
string s09                                  = input.symbol('TRXUSDT',  group = 'Symbols', inline = 's09',title = "Symbol 9")
string s10                                  = input.symbol('BTCBUSD',  group = 'Symbols', inline = 's10',title = "Symbol 10")
string s11                                  = input.symbol('ETHBUSD',  group = 'Symbols', inline = 's11',title = "Symbol 11")
string s12                                  = input.symbol('BNBBUSD',  group = 'Symbols', inline = 's12',title = "Symbol 12")
string s13                                  = input.symbol('VETUSDT',  group = 'Symbols', inline = 's13',title = "Symbol 13")
string s14                                  = input.symbol('ETHBTC',   group = 'Symbols', inline = 's14',title = "Symbol 14")
string s15                                  = input.symbol('BNBBTC',   group = 'Symbols', inline = 's15',title = "Symbol 15")
string s16                                  = input.symbol('EOSUSDT',  group = 'Symbols', inline = 's16',title = "Symbol 16")
string s17                                  = input.symbol('XLMUSDT',  group = 'Symbols', inline = 's17',title = "Symbol 17")
string s18                                  = input.symbol('LTCUSDT',  group = 'Symbols', inline = 's18',title = "Symbol 18")
string s19                                  = input.symbol('XRPBUSD',  group = 'Symbols', inline = 's19',title = "Symbol 19")
string s20                                  = input.symbol('WINUSDT',  group = 'Symbols', inline = 's20',title = "Symbol 20")
string s21                                  = input.symbol('DOTUSDT',  group = 'Symbols', inline = 's21',title = "Symbol 21")
string s22                                  = input.symbol('BTTUSDT',  group = 'Symbols', inline = 's22',title = "Symbol 22")
string s23                                  = input.symbol('BCHUSDT',  group = 'Symbols', inline = 's23',title = "Symbol 23")
string s24                                  = input.symbol('ADABTC',   group = 'Symbols', inline = 's24',title = "Symbol 24")
string s25                                  = input.symbol('IOSTUSDT', group = 'Symbols', inline = 's25',title = "Symbol 25")
string s26                                  = input.symbol('CHZUSDT',  group = 'Symbols', inline = 's26',title = "Symbol 26")
string s27                                  = input.symbol('LINKUSDT', group = 'Symbols', inline = 's27',title = "Symbol 27")
string s28                                  = input.symbol('TRXBTC',   group = 'Symbols', inline = 's28',title = "Symbol 28")
string s29                                  = input.symbol('DOGEBUSD', group = 'Symbols', inline = 's29',title = "Symbol 29")
string s30                                  = input.symbol('BTCEUR',   group = 'Symbols', inline = 's30',title = "Symbol 30")
string s31                                  = input.symbol('FILUSDT',  group = 'Symbols', inline = 's31',title = "Symbol 31")
string s32                                  = input.symbol('HOTUSDT',  group = 'Symbols', inline = 's32',title = "Symbol 32")
string s33                                  = input.symbol('SXPUSDT',  group = 'Symbols', inline = 's33',title = "Symbol 33")
string s34                                  = input.symbol('ADABUSD',  group = 'Symbols', inline = 's34',title = "Symbol 34")
string s35                                  = input.symbol('RVNUSDT',  group = 'Symbols', inline = 's35',title = "Symbol 35")
string s36                                  = input.symbol('ATOMUSDT', group = 'Symbols', inline = 's36',title = "Symbol 36")
string s37                                  = input.symbol('XRPBNB',   group = 'Symbols', inline = 's37',title = "Symbol 37")
string s38                                  = input.symbol('LTCBTC',   group = 'Symbols', inline = 's38',title = "Symbol 38")
string s39                                  = input.symbol('IOSTBTC',  group = 'Symbols', inline = 's39',title = "Symbol 39")
string s40                                  = input.symbol('GRTUSDT',  group = 'Symbols', inline = 's40',title = "Symbol 40")
[positive01 , negative01]                   = GetData(s01) ,       [positive02 , negative02]                   = GetData(s02)
[positive03 , negative03]                   = GetData(s03) ,       [positive04 , negative04]                   = GetData(s04)
[positive05 , negative05]                   = GetData(s05) ,       [positive06 , negative06]                   = GetData(s06)
[positive07 , negative07]                   = GetData(s07) ,       [positive08 , negative08]                   = GetData(s08)
[positive09 , negative09]                   = GetData(s09) ,       [positive10 , negative10]                   = GetData(s10)
[positive11 , negative11]                   = GetData(s11) ,       [positive12 , negative12]                   = GetData(s12)
[positive13 , negative13]                   = GetData(s13) ,       [positive14 , negative14]                   = GetData(s14)
[positive15 , negative15]                   = GetData(s15) ,       [positive16 , negative16]                   = GetData(s16)
[positive17 , negative17]                   = GetData(s17) ,       [positive18 , negative18]                   = GetData(s18)
[positive19 , negative19]                   = GetData(s19) ,       [positive20 , negative20]                   = GetData(s20)
[positive21 , negative21]                   = GetData(s21) ,       [positive22 , negative22]                   = GetData(s22)
[positive23 , negative23]                   = GetData(s23) ,       [positive24 , negative24]                   = GetData(s24)
[positive25 , negative25]                   = GetData(s25) ,       [positive26 , negative26]                   = GetData(s26)
[positive27 , negative27]                   = GetData(s27) ,       [positive28 , negative28]                   = GetData(s28)
[positive29 , negative29]                   = GetData(s29) ,       [positive30 , negative30]                   = GetData(s30)
[positive31 , negative31]                   = GetData(s31) ,       [positive32 , negative32]                   = GetData(s32)
[positive33 , negative33]                   = GetData(s33) ,       [positive34 , negative34]                   = GetData(s34)
[positive35 , negative35]                   = GetData(s35) ,       [positive36 , negative36]                   = GetData(s36)
[positive37 , negative37]                   = GetData(s37) ,       [positive38 , negative38]                   = GetData(s38)
[positive39 , negative39]                   = GetData(s39) ,       [positive40 , negative40]                   = GetData(s40)

// Lets add the symbols into array using array.form to write less close 

array<string> raw_names                     = 
     array.from(
         s01,s02,s03,s04,s05,s06,s07,s08,s09,s10,
         s11,s12,s13,s14,s15,s16,s17,s18,s19,s20,
         s21,s22,s23,s24,s25,s26,s27,s28,s29,s30,
         s31,s32,s33,s34,s35,s36,s37,s38,s39,s40
         )

for name in raw_names
    array.push(names, syminfo.ticker(name))

// Lets add the activation bool into array using array.form to write less close 

array<bool> raw_bools                     = 
     array.from(
         T01,T02,T03,T04,T05,T06,T07,T08,T09,T10,
         T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,
         T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,
         T31,T32,T33,T34,T35,T36,T37,T38,T39,T40
         )

for _bool in raw_bools
    array.push(USEbool, _bool)

// Lets add the Positive signals into array using array.form to write less close 

array<bool> raw_positive                     = 
     array.from(
         positive01,positive02,positive03,positive04,positive05,
         positive06,positive07,positive08,positive09,positive10,
         positive11,positive12,positive13,positive14,positive15,
         positive16,positive17,positive18,positive19,positive20,
         positive21,positive22,positive23,positive24,positive25,
         positive26,positive27,positive28,positive29,positive30,
         positive31,positive32,positive33,positive34,positive35,
         positive36,positive37,positive38,positive39,positive40
         )

for _pos in raw_positive
    array.push(rsi_pos, _pos)


// if the positive signal is false means we are in a Negative Trend .. So !
// We technically wouldn't require this negative signal. however, I included it for future purposes and potential utilization.
// 
array<bool> raw_negative                    = 
     array.from(
         negative01,negative02,negative03,negative04,negative05,
         negative06,negative07,negative08,negative09,negative10,
         negative11,negative12,negative13,negative14,negative15,
         negative16,negative17,negative18,negative19,negative20,
         negative21,negative22,negative23,negative24,negative25,
         negative26,negative27,negative28,negative29,negative30,
         negative31,negative32,negative33,negative34,negative35,
         negative36,negative37,negative38,negative39,negative40
         )

for _neg in raw_negative
    array.push(rsi_neg, _neg)




// lets have out table to show the signal .
if barstate.islast
    if show_table
        text_color = show_table ? color.rgb(210, 210, 210) : color.black
        table.cell(summary_table, 0, 0, table_name, bgcolor=color.from_gradient(close,low,high ,color.rgb(16, 194, 167), color.rgb(240, 141, 71)))
        table.cell(summary_table, 1, 0, "", bgcolor=color.from_gradient(close,low,high ,color.rgb(16, 194, 167), color.rgb(240, 141, 71)),text_halign = text.align_left)
        table.cell(summary_table, 2, 0, "", bgcolor=color.from_gradient(close,low,high ,color.rgb(16, 194, 167), color.rgb(240, 141, 71)),text_halign = text.align_left)
        table.cell(summary_table, 3, 0, "", bgcolor=color.from_gradient(close,low,high ,color.rgb(16, 194, 167), color.rgb(240, 141, 71)),text_halign = text.align_left)
        table.cell(summary_table, 4, 0, "", bgcolor=color.from_gradient(close,low,high ,color.rgb(16, 194, 167), color.rgb(240, 141, 71)),text_halign = text.align_left)

        table.merge_cells(summary_table, 0, 0, 4, 0)
        table.cell(summary_table, 0, 1, 'Symbol', bgcolor=color.rgb(120, 123, 134, 38),text_color = textcolos)
        table.cell(summary_table, 1, 1, 'Status', bgcolor=color.rgb(120, 123, 134, 38),text_color = textcolos)
        table.cell(summary_table, 3, 1, 'Symbol', bgcolor=color.rgb(120, 123, 134, 38),text_color = textcolos)
        table.cell(summary_table, 4, 1, 'Status', bgcolor=color.rgb(120, 123, 134, 38),text_color = textcolos)
        // first table 
        for i = 0 to 19
            if array.get(USEbool, i)
                table_cell(summary_table,(i+1)+ 1 , array.get(names, i),array.get(rsi_pos,i) ? "Positive" : "Negative",array.get(rsi_pos, i))
        // 2nd table
        for i = 20 to 39
            if array.get(USEbool, i)
                table_cell2(summary_table,(i-19) + 1 , array.get(names, i),array.get(rsi_pos,i) ? "Positive" : "Negative",array.get(rsi_pos, i))





// signal function
signal()=>
    for i = 0 to 39
        if array.get(rsi_pos, i)
            conditioin = true
            conditioin
sig = signal()
sig2 = not signal()
// plotting --
plotshape(sig and not sig[1], style=shape.labelup, location=location.belowbar, color=color.rgb(14, 232, 240), size=size.small,text = "P")   
plotshape(sig2 and not sig2[1], style=shape.labeldown, location=location.abovebar, color=color.rgb(250, 165, 7), size=size.small,text = "N")    