Divergence Screener [Mr_Zed]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MR_zed

//@version=5
indicator(title="Divergence Screener [Mr_Zed]", overlay = true,format=format.price)


indiSet     = input(false,  "═════════ DS Settings ════════")

len = input.int(title="RSI Period", minval=1, defval=14)
src = input(title="RSI Source", defval=close)

lbR = input(title="Pivot Lookback Right", defval=5)
lbL = input(title="Pivot Lookback Left", defval=5)

rangeUpper = input(title="Max of Lookback Range", defval=60)
rangeLower = input(title="Min of Lookback Range", defval=5)

screenList  = input(false,  "═════════ Screener ════════")

asset_01    = input.symbol("",title="Asset 01",inline = "asset_01")
asset_01_tf = input.timeframe('',title="TimeFrame",inline = "asset_01")

asset_02    = input.symbol("",title="Asset 02",inline = "asset_02")
asset_02_tf = input.timeframe('',title="TimeFrame",inline = "asset_02")

asset_03    = input.symbol("",title="Asset 03",inline = "asset_03")
asset_03_tf = input.timeframe('',title="TimeFrame",inline = "asset_03")

asset_04    = input.symbol("",title="Asset 04",inline = "asset_04")
asset_04_tf = input.timeframe('',title="TimeFrame",inline = "asset_04")

asset_05    = input.symbol("",title="Asset 05",inline = "asset_05")
asset_05_tf = input.timeframe('',title="TimeFrame",inline = "asset_05")

asset_06    = input.symbol("",title="Asset 06",inline = "asset_06")
asset_06_tf = input.timeframe('',title="TimeFrame",inline = "asset_06")

asset_07    = input.symbol("",title="Asset 07",inline = "asset_07")
asset_07_tf = input.timeframe('',title="TimeFrame",inline = "asset_07")

asset_08    = input.symbol("",title="Asset 08",inline = "asset_08")
asset_08_tf = input.timeframe('',title="TimeFrame",inline = "asset_08")

asset_09    = input.symbol("",title="Asset 09",inline = "asset_09")
asset_09_tf = input.timeframe('',title="TimeFrame",inline = "asset_09")

asset_10    = input.symbol("",title="Asset 10",inline = "asset_10")
asset_10_tf = input.timeframe('',title="TimeFrame",inline = "asset_10")

asset_11    = input.symbol("",title="Asset 11",inline = "asset_11")
asset_11_tf = input.timeframe('',title="TimeFrame",inline = "asset_11")

asset_12    = input.symbol("",title="Asset 12",inline = "asset_12")
asset_12_tf = input.timeframe('',title="TimeFrame",inline = "asset_12")

asset_13    = input.symbol("",title="Asset 13",inline = "asset_13")
asset_13_tf = input.timeframe('',title="TimeFrame",inline = "asset_13")

asset_14    = input.symbol("",title="Asset 14",inline = "asset_14")
asset_14_tf = input.timeframe('',title="TimeFrame",inline = "asset_14")

asset_15    = input.symbol("",title="Asset 15",inline = "asset_15")
asset_15_tf = input.timeframe('',title="TimeFrame",inline = "asset_15")

asset_16    = input.symbol("",title="Asset 16",inline = "asset_16")
asset_16_tf = input.timeframe('',title="TimeFrame",inline = "asset_16")

asset_17    = input.symbol("",title="Asset 17",inline = "asset_17")
asset_17_tf = input.timeframe('',title="TimeFrame",inline = "asset_17")

asset_18    = input.symbol("",title="Asset 18",inline = "asset_18")
asset_18_tf = input.timeframe('',title="TimeFrame",inline = "asset_18")

asset_19    = input.symbol("",title="Asset 19",inline = "asset_19")
asset_19_tf = input.timeframe('',title="TimeFrame",inline = "asset_19")

asset_20    = input.symbol("",title="Asset 20",inline = "asset_20")
asset_20_tf = input.timeframe('',title="TimeFrame",inline = "asset_20")

asset_21    = input.symbol("",title="Asset 21",inline = "asset_21")
asset_21_tf = input.timeframe('',title="TimeFrame",inline = "asset_21")

asset_22    = input.symbol("",title="Asset 22",inline = "asset_22")
asset_22_tf = input.timeframe('',title="TimeFrame",inline = "asset_22")

asset_23    = input.symbol("",title="Asset 23",inline = "asset_23")
asset_23_tf = input.timeframe('',title="TimeFrame",inline = "asset_23")

asset_24    = input.symbol("",title="Asset 24",inline = "asset_24")
asset_24_tf = input.timeframe('',title="TimeFrame",inline = "asset_24")

asset_25    = input.symbol("",title="Asset 25",inline = "asset_25")
asset_25_tf = input.timeframe('',title="TimeFrame",inline = "asset_25")

asset_26    = input.symbol("",title="Asset 26",inline = "asset_26")
asset_26_tf = input.timeframe('',title="TimeFrame",inline = "asset_26")

asset_27    = input.symbol("",title="Asset 27",inline = "asset_27")
asset_27_tf = input.timeframe('',title="TimeFrame",inline = "asset_27")

asset_28    = input.symbol("",title="Asset 28",inline = "asset_28")
asset_28_tf = input.timeframe('',title="TimeFrame",inline = "asset_28")

asset_29    = input.symbol("",title="Asset 29",inline = "asset_29")
asset_29_tf = input.timeframe('',title="TimeFrame",inline = "asset_29")

asset_30    = input.symbol("",title="Asset 30",inline = "asset_30")
asset_30_tf = input.timeframe('',title="TimeFrame",inline = "asset_30")

asset_31    = input.symbol("",title="Asset 31",inline = "asset_31")
asset_31_tf = input.timeframe('',title="TimeFrame",inline = "asset_31")

asset_32    = input.symbol("",title="Asset 32",inline = "asset_32")
asset_32_tf = input.timeframe('',title="TimeFrame",inline = "asset_32")

asset_33    = input.symbol("",title="Asset 33",inline = "asset_33")
asset_33_tf = input.timeframe('',title="TimeFrame",inline = "asset_33")

asset_34    = input.symbol("",title="Asset 34",inline = "asset_34")
asset_34_tf = input.timeframe('',title="TimeFrame",inline = "asset_34")

asset_35    = input.symbol("",title="Asset 35",inline = "asset_35")
asset_35_tf = input.timeframe('',title="TimeFrame",inline = "asset_35")

asset_36    = input.symbol("",title="Asset 36",inline = "asset_36")
asset_36_tf = input.timeframe('',title="TimeFrame",inline = "asset_36")

asset_37    = input.symbol("",title="Asset 37",inline = "asset_37")
asset_37_tf = input.timeframe('',title="TimeFrame",inline = "asset_37")

asset_38    = input.symbol("",title="Asset 38",inline = "asset_38")
asset_38_tf = input.timeframe('',title="TimeFrame",inline = "asset_38")

asset_39    = input.symbol("",title="Asset 39",inline = "asset_39")
asset_39_tf = input.timeframe('',title="TimeFrame",inline = "asset_39")

asset_40    = input.symbol("",title="Asset 40",inline = "asset_40")
asset_40_tf = input.timeframe('',title="TimeFrame",inline = "asset_40")



DivergenceIndicator() =>

    osc = ta.rsi(src, len)

    plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true
    phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true

    //------------------------------------------------------------------------------
    // Regular Bullish
    // Osc: Higher Low

    bars = ta.barssince(plFound[1] == true)
    isInRange = rangeLower <= bars and bars <= rangeUpper

    oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and isInRange//_inRange(plFound[1])
    priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)
    bullCond = priceLL and oscHL and plFound //and barstate.isconfirmed

    //-------------------------------------------------------------------
    // Regular Bearish
    // Osc: Lower High

    bars_2 = ta.barssince(phFound[1] == true)
    isInRange_2 = rangeLower <= bars_2 and bars_2 <= rangeUpper

    oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and isInRange_2
    priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)
    bearCond = priceHH and oscLH and phFound //and barstate.isconfirmed
    
    status = 0

    if bullCond and barstate.isconfirmed
        status := 2
    else if bearCond and barstate.isconfirmed
        status := 4 
    else if bullCond 
        status := 1
    else if bearCond
        status := 3

    status


//************************************************************************************************************
// Screener Logic
//************************************************************************************************************


checkStatus(value,ticker,tf) =>
    if value == 2
        alert("Bullish  Divergence\n on " + ticker + "\n Timeframe: "+tf,alert.freq_once_per_bar)
    else if value == 4
        alert("Bearish  Divergence\n on " + ticker + "\n Timeframe: "+tf,alert.freq_once_per_bar)
    0

asset_01_status    = asset_01 == '' ? 0 : request.security(asset_01, asset_01_tf,  DivergenceIndicator(),gaps = barmerge.gaps_off,lookahead=barmerge.lookahead_on) 
xx = asset_01 == '' ? 0 : checkStatus(asset_01_status,asset_01,asset_01_tf)

asset_02_status = asset_02 == '' ? 0 : request.security(asset_02, asset_02_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_02 == '' ? 0 : checkStatus(asset_02_status, asset_02, asset_02_tf)

asset_03_status = asset_03 == '' ? 0 : request.security(asset_03, asset_03_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_03 == '' ? 0 : checkStatus(asset_03_status, asset_03, asset_03_tf)

asset_04_status = asset_04 == '' ? 0 : request.security(asset_04, asset_04_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_04 == '' ? 0 : checkStatus(asset_04_status, asset_04, asset_04_tf)

asset_05_status = asset_05 == '' ? 0 : request.security(asset_05, asset_05_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_05 == '' ? 0 : checkStatus(asset_05_status, asset_05, asset_05_tf)

asset_06_status = asset_06 == '' ? 0 : request.security(asset_06, asset_06_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_06 == '' ? 0 : checkStatus(asset_06_status, asset_06, asset_06_tf)

asset_07_status = asset_07 == '' ? 0 : request.security(asset_07, asset_07_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_07 == '' ? 0 : checkStatus(asset_07_status, asset_07, asset_07_tf)

asset_08_status = asset_08 == '' ? 0 : request.security(asset_08, asset_08_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_08 == '' ? 0 : checkStatus(asset_08_status, asset_08, asset_08_tf)

asset_09_status = asset_09 == '' ? 0 : request.security(asset_09, asset_09_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_09 == '' ? 0 : checkStatus(asset_09_status, asset_09, asset_09_tf)

asset_10_status = asset_10 == '' ? 0 : request.security(asset_10, asset_10_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_10 == '' ? 0 : checkStatus(asset_10_status, asset_10, asset_10_tf)

asset_11_status = asset_11 == '' ? 0 : request.security(asset_11, asset_11_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_11 == '' ? 0 : checkStatus(asset_11_status, asset_11, asset_11_tf)

asset_12_status = asset_12 == '' ? 0 : request.security(asset_12, asset_12_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_12 == '' ? 0 : checkStatus(asset_12_status, asset_12, asset_12_tf)

asset_13_status = asset_13 == '' ? 0 : request.security(asset_13, asset_13_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_13 == '' ? 0 : checkStatus(asset_13_status, asset_13, asset_13_tf)

asset_14_status = asset_14 == '' ? 0 : request.security(asset_14, asset_14_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_14 == '' ? 0 : checkStatus(asset_14_status, asset_14, asset_14_tf)

asset_15_status = asset_15 == '' ? 0 : request.security(asset_15, asset_15_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_15 == '' ? 0 : checkStatus(asset_15_status, asset_15, asset_15_tf)

asset_16_status = asset_16 == '' ? 0 : request.security(asset_16, asset_16_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_16 == '' ? 0 : checkStatus(asset_16_status, asset_16, asset_16_tf)

asset_17_status = asset_17 == '' ? 0 : request.security(asset_17, asset_17_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_17 == '' ? 0 : checkStatus(asset_17_status, asset_17, asset_17_tf)

asset_18_status = asset_18 == '' ? 0 : request.security(asset_18, asset_18_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_18 == '' ? 0 : checkStatus(asset_18_status, asset_18, asset_18_tf)

asset_19_status = asset_19 == '' ? 0 : request.security(asset_19, asset_19_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_19 == '' ? 0 : checkStatus(asset_19_status, asset_19, asset_19_tf)

asset_20_status = asset_20 == '' ? 0 : request.security(asset_20, asset_20_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_20 == '' ? 0 : checkStatus(asset_20_status, asset_20, asset_20_tf)

asset_21_status = asset_21 == '' ? 0 : request.security(asset_21, asset_21_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_21 == '' ? 0 : checkStatus(asset_21_status, asset_21, asset_21_tf)

asset_22_status = asset_22 == '' ? 0 : request.security(asset_22, asset_22_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_22 == '' ? 0 : checkStatus(asset_22_status, asset_22, asset_22_tf)

asset_23_status = asset_23 == '' ? 0 : request.security(asset_23, asset_23_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_23 == '' ? 0 : checkStatus(asset_23_status, asset_23, asset_23_tf)

asset_24_status = asset_24 == '' ? 0 : request.security(asset_24, asset_24_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_24 == '' ? 0 : checkStatus(asset_24_status, asset_24, asset_24_tf)

asset_25_status = asset_25 == '' ? 0 : request.security(asset_25, asset_25_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_25 == '' ? 0 : checkStatus(asset_25_status, asset_25, asset_25_tf)

asset_26_status = asset_26 == '' ? 0 : request.security(asset_26, asset_26_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_26 == '' ? 0 : checkStatus(asset_26_status, asset_26, asset_26_tf)

asset_27_status = asset_27 == '' ? 0 : request.security(asset_27, asset_27_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_27 == '' ? 0 : checkStatus(asset_27_status, asset_27, asset_27_tf)

asset_28_status = asset_28 == '' ? 0 : request.security(asset_28, asset_28_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_28 == '' ? 0 : checkStatus(asset_28_status, asset_28, asset_28_tf)

asset_29_status = asset_29 == '' ? 0 : request.security(asset_29, asset_29_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_29 == '' ? 0 : checkStatus(asset_29_status, asset_29, asset_29_tf)

asset_30_status = asset_30 == '' ? 0 : request.security(asset_30, asset_30_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_30 == '' ? 0 : checkStatus(asset_30_status, asset_30, asset_30_tf)

asset_31_status = asset_31 == '' ? 0 : request.security(asset_31, asset_31_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_31 == '' ? 0 : checkStatus(asset_31_status, asset_31, asset_31_tf)

asset_32_status = asset_32 == '' ? 0 : request.security(asset_32, asset_32_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_32 == '' ? 0 : checkStatus(asset_32_status, asset_32, asset_32_tf)

asset_33_status = asset_33 == '' ? 0 : request.security(asset_33, asset_33_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_33 == '' ? 0 : checkStatus(asset_33_status, asset_33, asset_33_tf)

asset_34_status = asset_34 == '' ? 0 : request.security(asset_34, asset_34_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_34 == '' ? 0 : checkStatus(asset_34_status, asset_34, asset_34_tf)

asset_35_status = asset_35 == '' ? 0 : request.security(asset_35, asset_35_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_35 == '' ? 0 : checkStatus(asset_35_status, asset_35, asset_35_tf)

asset_36_status = asset_36 == '' ? 0 : request.security(asset_36, asset_36_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_36 == '' ? 0 : checkStatus(asset_36_status, asset_36, asset_36_tf)

asset_37_status = asset_37 == '' ? 0 : request.security(asset_37, asset_37_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_37 == '' ? 0 : checkStatus(asset_37_status, asset_37, asset_37_tf)

asset_38_status = asset_38 == '' ? 0 : request.security(asset_38, asset_38_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_38 == '' ? 0 : checkStatus(asset_38_status, asset_38, asset_38_tf)

asset_39_status = asset_39 == '' ? 0 : request.security(asset_39, asset_39_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_39 == '' ? 0 : checkStatus(asset_39_status, asset_39, asset_39_tf)

asset_40_status = asset_40 == '' ? 0 : request.security(asset_40, asset_40_tf, DivergenceIndicator(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
xx := asset_40 == '' ? 0 : checkStatus(asset_40_status, asset_40, asset_40_tf)



//bullish div
bullish_div  = ""
bullish_div := asset_01 != '' and asset_01_status == 1 ? bullish_div + asset_01 + " (Bullish) Timframe["+asset_01_tf+"]\n" : bullish_div
bullish_div := asset_02 != '' and asset_02_status == 1 ? bullish_div + asset_02 + " (Bullish) Timframe["+asset_02_tf+"]\n" : bullish_div
bullish_div := asset_03 != '' and asset_03_status == 1 ? bullish_div + asset_03 + " (Bullish) Timframe["+asset_03_tf+"]\n" : bullish_div
bullish_div := asset_04 != '' and asset_04_status == 1 ? bullish_div + asset_04 + " (Bullish) Timframe["+asset_04_tf+"]\n" : bullish_div
bullish_div := asset_05 != '' and asset_05_status == 1 ? bullish_div + asset_05 + " (Bullish) Timframe["+asset_05_tf+"]\n" : bullish_div
bullish_div := asset_06 != '' and asset_06_status == 1 ? bullish_div + asset_06 + " (Bullish) Timframe["+asset_06_tf+"]\n" : bullish_div
bullish_div := asset_07 != '' and asset_07_status == 1 ? bullish_div + asset_07 + " (Bullish) Timframe["+asset_07_tf+"]\n" : bullish_div
bullish_div := asset_08 != '' and asset_08_status == 1 ? bullish_div + asset_08 + " (Bullish) Timframe["+asset_08_tf+"]\n" : bullish_div
bullish_div := asset_09 != '' and asset_09_status == 1 ? bullish_div + asset_09 + " (Bullish) Timframe["+asset_09_tf+"]\n" : bullish_div
bullish_div := asset_10 != '' and asset_10_status == 1 ? bullish_div + asset_10 + " (Bullish) Timframe["+asset_10_tf+"]\n" : bullish_div
bullish_div := asset_11 != '' and asset_11_status == 1 ? bullish_div + asset_11 + " (Bullish) Timframe["+asset_11_tf+"]\n" : bullish_div
bullish_div := asset_12 != '' and asset_12_status == 1 ? bullish_div + asset_12 + " (Bullish) Timframe["+asset_12_tf+"]\n" : bullish_div
bullish_div := asset_13 != '' and asset_13_status == 1 ? bullish_div + asset_13 + " (Bullish) Timframe["+asset_13_tf+"]\n" : bullish_div
bullish_div := asset_14 != '' and asset_14_status == 1 ? bullish_div + asset_14 + " (Bullish) Timframe["+asset_14_tf+"]\n" : bullish_div
bullish_div := asset_15 != '' and asset_15_status == 1 ? bullish_div + asset_15 + " (Bullish) Timframe["+asset_15_tf+"]\n" : bullish_div
bullish_div := asset_16 != '' and asset_16_status == 1 ? bullish_div + asset_16 + " (Bullish) Timframe["+asset_16_tf+"]\n" : bullish_div
bullish_div := asset_17 != '' and asset_17_status == 1 ? bullish_div + asset_17 + " (Bullish) Timframe["+asset_17_tf+"]\n" : bullish_div
bullish_div := asset_18 != '' and asset_18_status == 1 ? bullish_div + asset_18 + " (Bullish) Timframe["+asset_18_tf+"]\n" : bullish_div
bullish_div := asset_19 != '' and asset_19_status == 1 ? bullish_div + asset_19 + " (Bullish) Timframe["+asset_19_tf+"]\n" : bullish_div
bullish_div := asset_20 != '' and asset_20_status == 1 ? bullish_div + asset_20 + " (Bullish) Timframe["+asset_20_tf+"]\n" : bullish_div
bullish_div := asset_21 != '' and asset_21_status == 1 ? bullish_div + asset_21 + " (Bullish) Timframe["+asset_21_tf+"]\n" : bullish_div
bullish_div := asset_22 != '' and asset_22_status == 1 ? bullish_div + asset_22 + " (Bullish) Timframe["+asset_22_tf+"]\n" : bullish_div
bullish_div := asset_23 != '' and asset_23_status == 1 ? bullish_div + asset_23 + " (Bullish) Timframe["+asset_23_tf+"]\n" : bullish_div
bullish_div := asset_24 != '' and asset_24_status == 1 ? bullish_div + asset_24 + " (Bullish) Timframe["+asset_24_tf+"]\n" : bullish_div
bullish_div := asset_25 != '' and asset_25_status == 1 ? bullish_div + asset_25 + " (Bullish) Timframe["+asset_25_tf+"]\n" : bullish_div
bullish_div := asset_26 != '' and asset_26_status == 1 ? bullish_div + asset_26 + " (Bullish) Timframe["+asset_26_tf+"]\n" : bullish_div
bullish_div := asset_27 != '' and asset_27_status == 1 ? bullish_div + asset_27 + " (Bullish) Timframe["+asset_27_tf+"]\n" : bullish_div
bullish_div := asset_28 != '' and asset_28_status == 1 ? bullish_div + asset_28 + " (Bullish) Timframe["+asset_28_tf+"]\n" : bullish_div
bullish_div := asset_29 != '' and asset_29_status == 1 ? bullish_div + asset_29 + " (Bullish) Timframe["+asset_29_tf+"]\n" : bullish_div
bullish_div := asset_30 != '' and asset_30_status == 1 ? bullish_div + asset_30 + " (Bullish) Timframe["+asset_30_tf+"]\n" : bullish_div
bullish_div := asset_31 != '' and asset_31_status == 1 ? bullish_div + asset_31 + " (Bullish) Timframe["+asset_31_tf+"]\n" : bullish_div
bullish_div := asset_32 != '' and asset_32_status == 1 ? bullish_div + asset_32 + " (Bullish) Timframe["+asset_32_tf+"]\n" : bullish_div
bullish_div := asset_33 != '' and asset_33_status == 1 ? bullish_div + asset_33 + " (Bullish) Timframe["+asset_33_tf+"]\n" : bullish_div
bullish_div := asset_34 != '' and asset_34_status == 1 ? bullish_div + asset_34 + " (Bullish) Timframe["+asset_34_tf+"]\n" : bullish_div
bullish_div := asset_35 != '' and asset_35_status == 1 ? bullish_div + asset_35 + " (Bullish) Timframe["+asset_35_tf+"]\n" : bullish_div
bullish_div := asset_36 != '' and asset_36_status == 1 ? bullish_div + asset_36 + " (Bullish) Timframe["+asset_36_tf+"]\n" : bullish_div
bullish_div := asset_37 != '' and asset_37_status == 1 ? bullish_div + asset_37 + " (Bullish) Timframe["+asset_37_tf+"]\n" : bullish_div
bullish_div := asset_38 != '' and asset_38_status == 1 ? bullish_div + asset_38 + " (Bullish) Timframe["+asset_38_tf+"]\n" : bullish_div
bullish_div := asset_39 != '' and asset_39_status == 1 ? bullish_div + asset_39 + " (Bullish) Timframe["+asset_39_tf+"]\n" : bullish_div
bullish_div := asset_40 != '' and asset_40_status == 1 ? bullish_div + asset_40 + " (Bullish) Timframe["+asset_40_tf+"]\n" : bullish_div



//bullish div
bearish_div  = ""
bearish_div := asset_01 != '' and asset_01_status == 3 ? bearish_div + asset_01 + " (Bearish) Timframe["+asset_01_tf+"]\n" : bearish_div
bearish_div := asset_02 != '' and asset_02_status == 3 ? bearish_div + asset_02 + " (Bearish) Timframe["+asset_02_tf+"]\n" : bearish_div
bearish_div := asset_03 != '' and asset_03_status == 3 ? bearish_div + asset_03 + " (Bearish) Timframe["+asset_03_tf+"]\n" : bearish_div
bearish_div := asset_04 != '' and asset_04_status == 3 ? bearish_div + asset_04 + " (Bearish) Timframe["+asset_04_tf+"]\n" : bearish_div
bearish_div := asset_05 != '' and asset_05_status == 3 ? bearish_div + asset_05 + " (Bearish) Timframe["+asset_05_tf+"]\n" : bearish_div
bearish_div := asset_06 != '' and asset_06_status == 3 ? bearish_div + asset_06 + " (Bearish) Timframe["+asset_06_tf+"]\n" : bearish_div
bearish_div := asset_07 != '' and asset_07_status == 3 ? bearish_div + asset_07 + " (Bearish) Timframe["+asset_07_tf+"]\n" : bearish_div
bearish_div := asset_08 != '' and asset_08_status == 3 ? bearish_div + asset_08 + " (Bearish) Timframe["+asset_08_tf+"]\n" : bearish_div
bearish_div := asset_09 != '' and asset_09_status == 3 ? bearish_div + asset_09 + " (Bearish) Timframe["+asset_09_tf+"]\n" : bearish_div
bearish_div := asset_10 != '' and asset_10_status == 3 ? bearish_div + asset_10 + " (Bearish) Timframe["+asset_10_tf+"]\n" : bearish_div
bearish_div := asset_11 != '' and asset_11_status == 3 ? bearish_div + asset_11 + " (Bearish) Timframe["+asset_11_tf+"]\n" : bearish_div
bearish_div := asset_12 != '' and asset_12_status == 3 ? bearish_div + asset_12 + " (Bearish) Timframe["+asset_12_tf+"]\n" : bearish_div
bearish_div := asset_13 != '' and asset_13_status == 3 ? bearish_div + asset_13 + " (Bearish) Timframe["+asset_13_tf+"]\n" : bearish_div
bearish_div := asset_14 != '' and asset_14_status == 3 ? bearish_div + asset_14 + " (Bearish) Timframe["+asset_14_tf+"]\n" : bearish_div
bearish_div := asset_15 != '' and asset_15_status == 3 ? bearish_div + asset_15 + " (Bearish) Timframe["+asset_15_tf+"]\n" : bearish_div
bearish_div := asset_16 != '' and asset_16_status == 3 ? bearish_div + asset_16 + " (Bearish) Timframe["+asset_16_tf+"]\n" : bearish_div
bearish_div := asset_17 != '' and asset_17_status == 3 ? bearish_div + asset_17 + " (Bearish) Timframe["+asset_17_tf+"]\n" : bearish_div
bearish_div := asset_18 != '' and asset_18_status == 3 ? bearish_div + asset_18 + " (Bearish) Timframe["+asset_18_tf+"]\n" : bearish_div
bearish_div := asset_19 != '' and asset_19_status == 3 ? bearish_div + asset_19 + " (Bearish) Timframe["+asset_19_tf+"]\n" : bearish_div
bearish_div := asset_20 != '' and asset_20_status == 3 ? bearish_div + asset_20 + " (Bearish) Timframe["+asset_20_tf+"]\n" : bearish_div
bearish_div := asset_21 != '' and asset_21_status == 3 ? bearish_div + asset_21 + " (Bearish) Timframe["+asset_21_tf+"]\n" : bearish_div
bearish_div := asset_22 != '' and asset_22_status == 3 ? bearish_div + asset_22 + " (Bearish) Timframe["+asset_22_tf+"]\n" : bearish_div
bearish_div := asset_23 != '' and asset_23_status == 3 ? bearish_div + asset_23 + " (Bearish) Timframe["+asset_23_tf+"]\n" : bearish_div
bearish_div := asset_24 != '' and asset_24_status == 3 ? bearish_div + asset_24 + " (Bearish) Timframe["+asset_24_tf+"]\n" : bearish_div
bearish_div := asset_25 != '' and asset_25_status == 3 ? bearish_div + asset_25 + " (Bearish) Timframe["+asset_25_tf+"]\n" : bearish_div
bearish_div := asset_26 != '' and asset_26_status == 3 ? bearish_div + asset_26 + " (Bearish) Timframe["+asset_26_tf+"]\n" : bearish_div
bearish_div := asset_27 != '' and asset_27_status == 3 ? bearish_div + asset_27 + " (Bearish) Timframe["+asset_27_tf+"]\n" : bearish_div
bearish_div := asset_28 != '' and asset_28_status == 3 ? bearish_div + asset_28 + " (Bearish) Timframe["+asset_28_tf+"]\n" : bearish_div
bearish_div := asset_29 != '' and asset_29_status == 3 ? bearish_div + asset_29 + " (Bearish) Timframe["+asset_29_tf+"]\n" : bearish_div
bearish_div := asset_30 != '' and asset_30_status == 3 ? bearish_div + asset_30 + " (Bearish) Timframe["+asset_30_tf+"]\n" : bearish_div
bearish_div := asset_31 != '' and asset_31_status == 3 ? bearish_div + asset_31 + " (Bearish) Timframe["+asset_31_tf+"]\n" : bearish_div
bearish_div := asset_32 != '' and asset_32_status == 3 ? bearish_div + asset_32 + " (Bearish) Timframe["+asset_32_tf+"]\n" : bearish_div
bearish_div := asset_33 != '' and asset_33_status == 3 ? bearish_div + asset_33 + " (Bearish) Timframe["+asset_33_tf+"]\n" : bearish_div
bearish_div := asset_34 != '' and asset_34_status == 3 ? bearish_div + asset_34 + " (Bearish) Timframe["+asset_34_tf+"]\n" : bearish_div
bearish_div := asset_35 != '' and asset_35_status == 3 ? bearish_div + asset_35 + " (Bearish) Timframe["+asset_35_tf+"]\n" : bearish_div
bearish_div := asset_36 != '' and asset_36_status == 3 ? bearish_div + asset_36 + " (Bearish) Timframe["+asset_36_tf+"]\n" : bearish_div
bearish_div := asset_37 != '' and asset_37_status == 3 ? bearish_div + asset_37 + " (Bearish) Timframe["+asset_37_tf+"]\n" : bearish_div
bearish_div := asset_38 != '' and asset_38_status == 3 ? bearish_div + asset_38 + " (Bearish) Timframe["+asset_38_tf+"]\n" : bearish_div
bearish_div := asset_39 != '' and asset_39_status == 3 ? bearish_div + asset_39 + " (Bearish) Timframe["+asset_39_tf+"]\n" : bearish_div
bearish_div := asset_40 != '' and asset_40_status == 3 ? bearish_div + asset_40 + " (Bearish) Timframe["+asset_40_tf+"]\n" : bearish_div


//--------------
// Prep Label Value
//--------------
var assetcount = asset_01=='' and asset_02=='' and asset_03=='' and asset_04=='' and asset_05=='' and asset_06=='' and asset_07=='' and asset_08=='' and asset_09=='' and asset_10=='' and asset_11=='' and asset_12=='' and asset_13=='' and asset_14=='' and asset_15=='' and asset_16=='' and asset_17=='' and asset_18=='' and asset_19=='' and asset_20=='' and asset_21=='' and asset_22=='' and asset_23=='' and asset_24=='' and asset_25=='' and asset_26=='' and asset_27=='' and asset_28=='' and asset_29=='' and asset_30=='' and asset_31=='' and asset_32=='' and asset_33=='' and asset_34=='' and asset_35=='' and asset_36=='' and asset_37=='' and asset_38=='' and asset_39=='' and asset_40=='' ? 0 : 1 
var brl        = "\n-----------------------\n"

title  = "Divergence Screener [Mr_Zed]"+brl


checklist   = assetcount==0 ? "No Asset Defined\nPlease update parameter " : ""
obList      = ""
osList      = ""


if(assetcount>0)
    if(bullish_div != "")
        obList := "\nBullish List: "+brl+bullish_div
    
    if(bearish_div != "")
        osList := "\nBearish List: "+brl+bearish_div
    
    if(obList=="" and osList == "")
        checklist := "Nothing Interesting"


//--------------
// Draw Label
//--------------
label _lbl  = label.new(time, close, xloc=xloc.bar_time,
  text      = title + checklist + osList + obList,
  color     = color.black, 
  style     = label.style_label_left, 
  textcolor = color.white,
  size      = size.normal, 
  textalign = text.align_left)
  
label.set_x(_lbl, label.get_x(_lbl) + math.round(ta.change(time)*10))
label.delete(_lbl[1])
