MA Cross Screener
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © peacefulLizard50262

//@version=5
indicator("MA Cross Screener", overlay = false, precision = 0)
 
ma(src, len, type)=>
    switch type
        "SMA" => ta.sma(src, len)
        "EMA" => ta.ema(src, len)
        "WMA" => ta.wma(src, len)

select = input.string("MA Cross", "Strategy Select", ["MA Cross", "RSI", "MACD", "Stochastic", "200 MA"], group = "Settings")
custom = input.bool(false, "Custom Time Frame", inline = "Time", tooltip = "When using custom time frame use the minimum time on your chart.", group = "Settings")
ctime  = input.timeframe("D", "", inline = "Time", group = "Settings")

txt_col = input.color(color.new(color.black, 0), "Title Color", inline = "bull", group = "Settings")
box_col = input.color(color.new(color.white, 0), "", inline = "bull", group = "Settings")
sig_col2 = input.color(color.new(color.red, 0), "Signal Color", inline = "bull", group = "Settings")
sig_col1 = input.color(color.new(color.green, 0), "", inline = "bull", group = "Settings")

fast  = input.int(9, "Fast Length", 1, group = "MA Cross")
slow  = input.int(21, "Slow Length", 1, group = "MA Cross")
type  = input.string("EMA", "MA Type Fast", ["SMA","EMA","WMA"], group = "MA Cross")
type2 = input.string("EMA", "MA Type Slow", ["SMA","EMA","WMA"], group = "MA Cross")

rsi_length = input.int(14, "RSI Length", 1, group = "RSI")
rsi_high   = input.int(70 , "RSI High Threshold", group = "RSI")
rsi_low    = input.int(30 , "RSI Low Threshold", group = "RSI")

macd_fast   = input.int(12 , "MACD", 1, group = "MACD")
macd_slow   = input.int(26 , "MACD", 1, group = "MACD")
macd_siglen = input.int(9 , "MACD", 1, group = "MACD")

stoch_len = input.int(14, group = "Stochastic")
stoch_smo = input.int(1, group = "Stochastic")
stoch_hi  = input.int(80 , "Stochastic High Threshold", group = "Stochastic")
stoch_lo  = input.int(20 , "Stochastic Low Threshold", group = "Stochastic")

ma_length = input.int(200, "MA '200' Length", 1, group = "MA 200")

timep = custom ? ctime : timeframe.period

main(src, n) =>

    exn  = str.tostring(src)
    var color col = na
    var label lab = na
    label.delete(lab)
    lab := label.new(bar_index + 5, n, exn, textcolor = txt_col, color = box_col)
 
    sig_p  = false 
    sig_q  = false

    ex  = request.security(src , timep, close)
    exh = ta.highest(ex, 1)
    exl = ta.lowest(ex, 1)

    fast_n = ma(ex, fast, type)
    slow_n = ma(ex, slow, type2)

    rsi = ta.rsi(ex, rsi_length)

    [macd1, macd2, hist] = ta.macd(ex, macd_fast, macd_slow, macd_siglen)

    stoch = ta.sma(ta.stoch(ex, exh, exl, stoch_len), stoch_smo)

    ma200 = ta.sma(ex, ma_length)

    logic_up = switch select
        "MA Cross"   => ta.crossover(fast_n, slow_n)
        "RSI"        => ta.crossover(rsi, rsi_high)
        "MACD"       => ta.crossover(macd1, macd2)
        "Stochastic" => ta.crossover(stoch, rsi_low)
        "200 MA"     => ta.crossover(ex, ma200)
    logic_down = switch select
        "MA Cross"   => ta.crossunder(fast_n, slow_n)
        "RSI"        => ta.crossover(rsi, stoch_hi)
        "MACD"       => ta.crossunder(macd1, macd2)
        "Stochastic" => ta.crossover(stoch, stoch_lo)
        "200 MA"     => ta.crossunder(ex, ma200)

    if logic_up
        alert("Symbol " + exn + " crossed up")
        col   := sig_col1
        sig_p := true
        sig_q := true
    if logic_down 
        alert("Symbol " + exn + " crossed down")
        col   := sig_col2
        sig_p := true
        sig_q := true

    [sig_p, sig_q, col]


ext1  = input.symbol('BTCUSD', 'Symbol 1', group = "Symbols")
ext2  = input.symbol('ETHUSD', 'Symbol 2', group = "Symbols")
ext3  = input.symbol('BNBUSD', 'Symbol 3', group = "Symbols")
ext4  = input.symbol('XRPUSD', 'Symbol 4', group = "Symbols")
ext5  = input.symbol('DOGEUSD', 'Symbol 5', group = "Symbols")
ext6  = input.symbol('ETCUSD', 'Symbol 6', group = "Symbols")
ext7  = input.symbol('LTCUSD', 'Symbol 7', group = "Symbols")
ext8  = input.symbol('XLMUSD', 'Symbol 8', group = "Symbols")
ext9  = input.symbol('XMRUSD', 'Symbol 9', group = "Symbols")
ext10 = input.symbol('TRXUSD', 'Symbol 10', group = "Symbols")
ext11 = input.symbol('AAPL', 'Symbol 11', group = "Symbols")
ext12 = input.symbol('MSFT', 'Symbol 12', group = "Symbols")
ext13 = input.symbol('GOOG', 'Symbol 13', group = "Symbols")
ext14 = input.symbol('AMZN', 'Symbol 14', group = "Symbols")
ext15 = input.symbol('TSLA', 'Symbol 15', group = "Symbols")
ext16 = input.symbol('UNH', 'Symbol 16', group = "Symbols")
ext17 = input.symbol('META', 'Symbol 17', group = "Symbols")
ext18 = input.symbol('NVDA', 'Symbol 18', group = "Symbols")
ext19 = input.symbol('V', 'Symbol 19', group = "Symbols")
ext20 = input.symbol('MA', 'Symbol 20', group = "Symbols")

[sig, sig20, col1] = main(ext1, 1)
[sig1, sig21, col2] = main(ext2, 2)
[sig2, sig22, col3] = main(ext3, 3)
[sig3, sig23, col4] = main(ext4, 4)
[sig4, sig24, col5] = main(ext5, 5)
[sig5, sig25, col6] = main(ext6, 6)
[sig6, sig26, col7] = main(ext7, 7)
[sig7, sig27, col8] = main(ext8, 8)
[sig8, sig28, col9] = main(ext9, 9)
[sig9, sig29, col10] = main(ext10, 10)
[sig10, sig30, col11] = main(ext11, 11)
[sig11, sig31, col12] = main(ext12, 12)
[sig12, sig32, col13] = main(ext13, 13)
[sig13, sig33, col14] = main(ext14, 14)
[sig14, sig34, col15] = main(ext15, 15)
[sig15, sig35, col16] = main(ext16, 16)
[sig16, sig36, col17] = main(ext17, 17)
[sig17, sig37, col18] = main(ext18, 18)
[sig18, sig38, col19] = main(ext19, 19)
[sig19, sig39, col20] = main(ext20, 20)

plotshape(sig or sig20 ? 1 : na, location = location.absolute, color = col1, style = shape.circle)
plotshape(sig1 or sig21 ? 2 : na, location = location.absolute, color = col2, style = shape.circle)
plotshape(sig2 or sig22 ? 3 : na, location = location.absolute, color = col3, style = shape.circle)
plotshape(sig3 or sig23 ? 4 : na, location = location.absolute, color = col4, style = shape.circle)
plotshape(sig4 or sig24 ? 5 : na, location = location.absolute, color = col5, style = shape.circle)
plotshape(sig5 or sig25 ? 6 : na, location = location.absolute, color = col6, style = shape.circle)
plotshape(sig6 or sig26 ? 7 : na, location = location.absolute, color = col7, style = shape.circle)
plotshape(sig7 or sig27 ? 8 : na, location = location.absolute, color = col8, style = shape.circle)
plotshape(sig8 or sig28 ? 9 : na, location = location.absolute, color = col9, style = shape.circle)
plotshape(sig9 or sig29 ? 10 : na, location = location.absolute, color = col10, style = shape.circle)
plotshape(sig10 or sig30 ? 11 : na, location = location.absolute, color = col11, style = shape.circle)
plotshape(sig11 or sig31 ? 12 : na, location = location.absolute, color = col12, style = shape.circle)
plotshape(sig12 or sig32 ? 13 : na, location = location.absolute, color = col13, style = shape.circle)
plotshape(sig13 or sig33 ? 14 : na, location = location.absolute, color = col14, style = shape.circle)
plotshape(sig14 or sig34 ? 15 : na, location = location.absolute, color = col15, style = shape.circle)
plotshape(sig15 or sig35 ? 16 : na, location = location.absolute, color = col16, style = shape.circle)
plotshape(sig16 or sig36 ? 17 : na, location = location.absolute, color = col17, style = shape.circle)
plotshape(sig17 or sig37 ? 18 : na, location = location.absolute, color = col18, style = shape.circle)
plotshape(sig18 or sig38 ? 19 : na, location = location.absolute, color = col19, style = shape.circle)
plotshape(sig19 or sig39 ? 20 : na, location = location.absolute, color = col20, style = shape.circle)

hline(1, color = color.new(color.gray, 90))
hline(2, color = color.new(color.gray, 90))
hline(3, color = color.new(color.gray, 90))
hline(4, color = color.new(color.gray, 90))
hline(5, color = color.new(color.gray, 90))
hline(6, color = color.new(color.gray, 90))
hline(7, color = color.new(color.gray, 90))
hline(8, color = color.new(color.gray, 90))
hline(9, color = color.new(color.gray, 90))
hline(10, color = color.new(color.gray, 90))
hline(11, color = color.new(color.gray, 90))
hline(12, color = color.new(color.gray, 90))
hline(13, color = color.new(color.gray, 90))
hline(14, color = color.new(color.gray, 90))
hline(15, color = color.new(color.gray, 90))
hline(16, color = color.new(color.gray, 90))
hline(17, color = color.new(color.gray, 90))
hline(18, color = color.new(color.gray, 90))
hline(19, color = color.new(color.gray, 90))
hline(20, color = color.new(color.gray, 90))