QFL Screener [ ZCrypto ]
// 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("QFL Screener [ ZCrypto ]",shorttitle = "QFL Screener",overlay = true)


string table_name                           ='QFL Screener [ZCrypto]'
string table_Group                          = "Table"     
string settings_Group                       = "Core Settings"
var float base                              = na
var float lowrange                          = na
bool buySignal                              = false
bool buySignal2                             = false
int ra                                      = 80
float savezone                              = 2.0
float signal                                = 0.0
float szone                                 = 0.0
float rangeHigh                             = ta.highest(high, ra) 
float rangeLow                              = ta.lowest(low, ra)
float stochValue                            = ta.sma(ta.stoch(close, high, low, 14), 3)
int CheckThreshold                          = input.int(8,group = settings_Group,inline = "1",
     tooltip = "set the percentage threshold for checking the higher peak"
     )

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)

string freq                                 = input.string("once per bar close", 
     options = ["freq all","once per bar","once per bar close"],
     title = 'Alert frequency',
     inline = "002",
     group = "Alerts"
     )
bool backtest                               = input.bool(false,"Activate Backtesting❓",group = "Testing",inline = "001")
int testvalue                               = input.int(100,group = "Testing",inline = "001",title = "Value") 

// Arrays
array<string> names                     = array.new_string(0)
array<bool> USEbool                     = array.new_bool(0)
array<bool> qfl_arr                     = array.new_bool(0)

//----Alerts ----{   
alert_freq() =>
    switch freq
        "freq all" => alert.freq_all
        "once per bar" => alert.freq_once_per_bar
        "once per bar close" => alert.freq_once_per_bar_close 

//----Table ----{   

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(0, 149, 77) : color.rgb(152, 46, 46)    
 
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))    

//-- }

////////////
// SYMBOLS // 

u01 = input.bool(true,  title = "", group = 'Symbols', inline = 's01')
u02 = input.bool(true,  title = "", group = 'Symbols', inline = 's02')
u03 = input.bool(true,  title = "", group = 'Symbols', inline = 's03')
u04 = input.bool(true,  title = "", group = 'Symbols', inline = 's04')
u05 = input.bool(true,  title = "", group = 'Symbols', inline = 's05')
u06 = input.bool(true,  title = "", group = 'Symbols', inline = 's06')
u07 = input.bool(true,  title = "", group = 'Symbols', inline = 's07')
u08 = input.bool(true,  title = "", group = 'Symbols', inline = 's08')
u09 = input.bool(true,  title = "", group = 'Symbols', inline = 's09')
u10 = input.bool(true,  title = "", group = 'Symbols', inline = 's10')
u11 = input.bool(true,  title = "", group = 'Symbols', inline = 's11')
u12 = input.bool(true,  title = "", group = 'Symbols', inline = 's12')
u13 = input.bool(true,  title = "", group = 'Symbols', inline = 's13')
u14 = input.bool(true,  title = "", group = 'Symbols', inline = 's14')
u15 = input.bool(true,  title = "", group = 'Symbols', inline = 's15')
u16 = input.bool(true,  title = "", group = 'Symbols', inline = 's16')
u17 = input.bool(true,  title = "", group = 'Symbols', inline = 's17')
u18 = input.bool(true,  title = "", group = 'Symbols', inline = 's18')
u19 = input.bool(true,  title = "", group = 'Symbols', inline = 's19')
u20 = input.bool(true,  title = "", group = 'Symbols', inline = 's20')
u21 = input.bool(true,  title = "", group = 'Symbols', inline = 's21')
u22 = input.bool(true,  title = "", group = 'Symbols', inline = 's22')
u23 = input.bool(true,  title = "", group = 'Symbols', inline = 's23')
u24 = input.bool(true,  title = "", group = 'Symbols', inline = 's24')
u25 = input.bool(true,  title = "", group = 'Symbols', inline = 's25')
u26 = input.bool(true,  title = "", group = 'Symbols', inline = 's26')
u27 = input.bool(true,  title = "", group = 'Symbols', inline = 's27')
u28 = input.bool(true,  title = "", group = 'Symbols', inline = 's28')
u29 = input.bool(true,  title = "", group = 'Symbols', inline = 's29')
u30 = input.bool(true,  title = "", group = 'Symbols', inline = 's30')
u31 = input.bool(true,  title = "", group = 'Symbols', inline = 's31')
u32 = input.bool(true,  title = "", group = 'Symbols', inline = 's32')
u33 = input.bool(true,  title = "", group = 'Symbols', inline = 's33')
u34 = input.bool(true,  title = "", group = 'Symbols', inline = 's34')
u35 = input.bool(true,  title = "", group = 'Symbols', inline = 's35')
u36 = input.bool(true, title = "", group = 'Symbols', inline = 's36')
u37 = input.bool(true, title = "", group = 'Symbols', inline = 's37')
u38 = input.bool(true, title = "", group = 'Symbols', inline = 's38')
u39 = input.bool(true, title = "", group = 'Symbols', inline = 's39')
u40 = input.bool(true, title = "", group = 'Symbols', inline = 's40')

s01 = input.symbol('XRPUSDT',  group = 'Symbols', inline = 's01',title = "Symbol 1")
s02 = input.symbol('BTCUSDT',  group = 'Symbols', inline = 's02',title = "Symbol 2")
s03 = input.symbol('DOGEUSDT', group = 'Symbols', inline = 's03',title = "Symbol 3")
s04 = input.symbol('BNBUSDT',  group = 'Symbols', inline = 's04',title = "Symbol 4")
s05 = input.symbol('ETHUSDT',  group = 'Symbols', inline = 's05',title = "Symbol 5")
s06 = input.symbol('ADAUSDT',  group = 'Symbols', inline = 's06',title = "Symbol 6")
s07 = input.symbol('XRPBTC',   group = 'Symbols', inline = 's07',title = "Symbol 7")
s08 = input.symbol('DOGEBTC',  group = 'Symbols', inline = 's08',title = "Symbol 8")
s09 = input.symbol('TRXUSDT',  group = 'Symbols', inline = 's09',title = "Symbol 9")
s10 = input.symbol('BTCBUSD',  group = 'Symbols', inline = 's10',title = "Symbol 10")
s11 = input.symbol('ETHBUSD',  group = 'Symbols', inline = 's11',title = "Symbol 11")
s12 = input.symbol('BNBBUSD',  group = 'Symbols', inline = 's12',title = "Symbol 12")
s13 = input.symbol('VETUSDT',  group = 'Symbols', inline = 's13',title = "Symbol 13")
s14 = input.symbol('ETHBTC',   group = 'Symbols', inline = 's14',title = "Symbol 14")
s15 = input.symbol('BNBBTC',   group = 'Symbols', inline = 's15',title = "Symbol 15")
s16 = input.symbol('EOSUSDT',  group = 'Symbols', inline = 's16',title = "Symbol 16")
s17 = input.symbol('XLMUSDT',  group = 'Symbols', inline = 's17',title = "Symbol 17")
s18 = input.symbol('LTCUSDT',  group = 'Symbols', inline = 's18',title = "Symbol 18")
s19 = input.symbol('XRPBUSD',  group = 'Symbols', inline = 's19',title = "Symbol 19")
s20 = input.symbol('WINUSDT',  group = 'Symbols', inline = 's20',title = "Symbol 20")
s21 = input.symbol('DOTUSDT',  group = 'Symbols', inline = 's21',title = "Symbol 21")
s22 = input.symbol('BTTUSDT',  group = 'Symbols', inline = 's22',title = "Symbol 22")
s23 = input.symbol('BCHUSDT',  group = 'Symbols', inline = 's23',title = "Symbol 23")
s24 = input.symbol('ADABTC',   group = 'Symbols', inline = 's24',title = "Symbol 24")
s25 = input.symbol('IOSTUSDT', group = 'Symbols', inline = 's25',title = "Symbol 25")
s26 = input.symbol('CHZUSDT',  group = 'Symbols', inline = 's26',title = "Symbol 26")
s27 = input.symbol('LINKUSDT', group = 'Symbols', inline = 's27',title = "Symbol 27")
s28 = input.symbol('TRXBTC',   group = 'Symbols', inline = 's28',title = "Symbol 28")
s29 = input.symbol('DOGEBUSD', group = 'Symbols', inline = 's29',title = "Symbol 29")
s30 = input.symbol('BTCEUR',   group = 'Symbols', inline = 's30',title = "Symbol 30")
s31 = input.symbol('FILUSDT',  group = 'Symbols', inline = 's31',title = "Symbol 31")
s32 = input.symbol('HOTUSDT',  group = 'Symbols', inline = 's32',title = "Symbol 32")
s33 = input.symbol('SXPUSDT',  group = 'Symbols', inline = 's33',title = "Symbol 33")
s34 = input.symbol('ADABUSD',  group = 'Symbols', inline = 's34',title = "Symbol 34")
s35 = input.symbol('RVNUSDT',  group = 'Symbols', inline = 's35',title = "Symbol 35")
s36 = input.symbol('ATOMUSDT', group = 'Symbols', inline = 's36',title = "Symbol 36")
s37 = input.symbol('XRPBNB',   group = 'Symbols', inline = 's37',title = "Symbol 37")
s38 = input.symbol('LTCBTC',   group = 'Symbols', inline = 's38',title = "Symbol 38")
s39 = input.symbol('IOSTBTC',  group = 'Symbols', inline = 's39',title = "Symbol 39")
s40 = input.symbol('GRTUSDT',  group = 'Symbols', inline = 's40',title = "Symbol 40")


get_data(pair) =>
    [r_high,r_low,lows] = request.security(pair,timeframe.period, [rangeHigh,rangeLow,low])

check_for_qfl(pair) =>
    [highz,lowz,lows] = get_data(pair)
    rangez = math.abs(lowz - highz) /lowz  * 100
    if (lows == lowz) and rangez >= CheckThreshold
        szone == math.abs((lows[1] - lows) /lows[1])  * 100
        if szone >= savezone
            false
        else
            true


// Security call
qfl01 = check_for_qfl(s01)
qfl02 = check_for_qfl(s02)
qfl03 = check_for_qfl(s03)
qfl04 = check_for_qfl(s04)
qfl05 = check_for_qfl(s05)
qfl06 = check_for_qfl(s06)
qfl07 = check_for_qfl(s07)
qfl08 = check_for_qfl(s08)
qfl09 = check_for_qfl(s09)
qfl10 = check_for_qfl(s10)
qfl11 = check_for_qfl(s11)
qfl12 = check_for_qfl(s12)
qfl13 = check_for_qfl(s13)
qfl14 = check_for_qfl(s14)
qfl15 = check_for_qfl(s15)
qfl16 = check_for_qfl(s16)
qfl17 = check_for_qfl(s17)
qfl18 = check_for_qfl(s18)
qfl19 = check_for_qfl(s19)
qfl20 = check_for_qfl(s20)
qfl21 = check_for_qfl(s21)
qfl22 = check_for_qfl(s22)
qfl23 = check_for_qfl(s23)
qfl24 = check_for_qfl(s24)
qfl25 = check_for_qfl(s25)
qfl26 = check_for_qfl(s26)
qfl27 = check_for_qfl(s27)
qfl28 = check_for_qfl(s28)
qfl29 = check_for_qfl(s29)
qfl30 = check_for_qfl(s30)
qfl31 = check_for_qfl(s31)
qfl32 = check_for_qfl(s32)
qfl33 = check_for_qfl(s33)
qfl34 = check_for_qfl(s34)
qfl35 = check_for_qfl(s35)
qfl36 = check_for_qfl(s36)
qfl37 = check_for_qfl(s37)
qfl38 = check_for_qfl(s38)
qfl39 = check_for_qfl(s39)
qfl40 = check_for_qfl(s40)




//  Lets add symbols to array for table and alerts 

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

// Lets add bools to array for table and alerts
array.push(USEbool, u01)
array.push(USEbool, u02)
array.push(USEbool, u03)
array.push(USEbool, u04)
array.push(USEbool, u05)
array.push(USEbool, u06)
array.push(USEbool, u07)
array.push(USEbool, u08)
array.push(USEbool, u09)
array.push(USEbool, u10)
array.push(USEbool, u11)
array.push(USEbool, u12)
array.push(USEbool, u13)
array.push(USEbool, u14)
array.push(USEbool, u15)
array.push(USEbool, u16)
array.push(USEbool, u17)
array.push(USEbool, u18)
array.push(USEbool, u19)
array.push(USEbool, u20)
array.push(USEbool, u21)
array.push(USEbool, u22)
array.push(USEbool, u23)
array.push(USEbool, u24)
array.push(USEbool, u25)
array.push(USEbool, u26)
array.push(USEbool, u27)
array.push(USEbool, u28)
array.push(USEbool, u29)
array.push(USEbool, u30)
array.push(USEbool, u31)
array.push(USEbool, u32)
array.push(USEbool, u33)
array.push(USEbool, u34)
array.push(USEbool, u35)
array.push(USEbool, u36)
array.push(USEbool, u37)
array.push(USEbool, u38)
array.push(USEbool, u39)
array.push(USEbool, u40)



// QFL signal to array for table and alerts 

array.push(qfl_arr, qfl01)
array.push(qfl_arr, qfl02)
array.push(qfl_arr, qfl03)
array.push(qfl_arr, qfl04)
array.push(qfl_arr, qfl05)
array.push(qfl_arr, qfl06)
array.push(qfl_arr, qfl07)
array.push(qfl_arr, qfl08)
array.push(qfl_arr, qfl09)
array.push(qfl_arr, qfl10)
array.push(qfl_arr, qfl11)
array.push(qfl_arr, qfl12)
array.push(qfl_arr, qfl13)
array.push(qfl_arr, qfl14)
array.push(qfl_arr, qfl15)
array.push(qfl_arr, qfl16)
array.push(qfl_arr, qfl17)
array.push(qfl_arr, qfl18)
array.push(qfl_arr, qfl19)
array.push(qfl_arr, qfl20)
array.push(qfl_arr, qfl21)
array.push(qfl_arr, qfl22)
array.push(qfl_arr, qfl23)
array.push(qfl_arr, qfl24)
array.push(qfl_arr, qfl25)
array.push(qfl_arr, qfl26)
array.push(qfl_arr, qfl27)
array.push(qfl_arr, qfl28)
array.push(qfl_arr, qfl29)
array.push(qfl_arr, qfl30)
array.push(qfl_arr, qfl31)
array.push(qfl_arr, qfl32)
array.push(qfl_arr, qfl33)
array.push(qfl_arr, qfl34)
array.push(qfl_arr, qfl35)
array.push(qfl_arr, qfl36)
array.push(qfl_arr, qfl37)
array.push(qfl_arr, qfl38)
array.push(qfl_arr, qfl39)
array.push(qfl_arr, qfl40)

// plotshape(conditioin, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)        


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(qfl_arr, i) ? "True" : "False",array.get(qfl_arr, 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(qfl_arr, i) ? "True" : "False",array.get(qfl_arr, i))



// alert function
Alertz()=>
    for i = 0 to 39
        if array.get(qfl_arr, i)
            conditioin = true
            alert(message = array.get(names, i) +" Fired QFL Signal",freq = alert_freq())
            conditioin

Alert = Alertz()

// plotting --
plot(backtest and Alert ? testvalue : 0,title = "QFL Signal",display = display.none)
plotshape(Alert, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)        