Crypto Scannner for Traffic Lights Strategy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © maxits

//@version=4

study("Crypto Scannner", overlay=false)
offset = input(defval=20, title="Number of Bars offset", type=input.integer)
TL() =>
    
    fema   = ema(close, 8)
    mema   = ema(close, 14)
    sema   = ema(close, 16)
    filter = ema(close, 600)
    
    goLong  = fema > mema and mema > sema and fema > filter
    goShort = fema < mema and mema < sema and fema < filter
    
    position = goLong or goShort
    
s1  = security("BINANCE:BTCUSDT",  "240", TL())
s2  = security("BINANCE:ETHUSDT",  "240", TL())
s3  = security("BINANCE:BNBUSDT",  "240", TL())
s4  = security("BINANCE:ADAUSDT",  "240", TL())
s5  = security("BINANCE:LTCUSDT",  "240", TL())
s6  = security("BINANCE:BCHUSDT",  "240", TL())
s7  = security("BINANCE:LINKUSDT", "240", TL())
s8  = security("BINANCE:SOLUSDT",  "240", TL())
s9  = security("BINANCE:AVAXUSDT", "240", TL())
s10 = security("BINANCE:LUNAUSDT", "240", TL())
s11 = security("BINANCE:ALGOUSDT", "240", TL())

scr_label  = "Screener: Traffic Lights" + "\n4H Chart" + "\nLong + Short Conditions" + "\n======================"
scr_label := s1  ? scr_label + "\nBTCUSDT"  : scr_label 
scr_label := s2  ? scr_label + "\nETHUSDT"  : scr_label 
scr_label := s3  ? scr_label + "\nBNBUSDT"  : scr_label 
scr_label := s4  ? scr_label + "\nADAUSDT"  : scr_label 
scr_label := s5  ? scr_label + "\nLTCUSDT"  : scr_label 
scr_label := s6  ? scr_label + "\nBCHUSDT"  : scr_label 
scr_label := s7  ? scr_label + "\nLINKUSDT" : scr_label 
scr_label := s8  ? scr_label + "\nSOLUSDT"  : scr_label 
scr_label := s9  ? scr_label + "\nAVAXUSDT" : scr_label 
scr_label := s10 ? scr_label + "\nLUNAUSDT" : scr_label 
scr_label := s11 ? scr_label + "\nALGOSDT"  : scr_label 


a_label = label.new(bar_index - offset, 0, scr_label,
                     color=color.new(color.red, 0),
                     textcolor=color.new(color.white, 0))
label.delete(a_label[1])



TLchange() =>
    
    fema   = ema(close, 8)
    mema   = ema(close, 14)
    sema   = ema(close, 16)
    filter = ema(close, 600)
    
    goLong  = fema > mema and mema > sema and fema > filter
    goShort = fema < mema and mema < sema and fema < filter
    
    position = goLong or goShort
    change = position[1] != position or position[2] != position or position[3] != position or position[4] != position or position[5] != position or position[6] != position

c_s1  = security("BINANCE:BTCUSDT",  "240", TLchange())
c_s2  = security("BINANCE:ETHUSDT",  "240", TLchange())
c_s3  = security("BINANCE:BNBUSDT",  "240", TLchange())
c_s4  = security("BINANCE:ADAUSDT",  "240", TLchange())
c_s5  = security("BINANCE:LTCUSDT",  "240", TLchange())
c_s6  = security("BINANCE:BCHUSDT",  "240", TLchange())
c_s7  = security("BINANCE:LINKUSDT", "240", TLchange())
c_s8  = security("BINANCE:SOLUSDT",  "240", TLchange())
c_s9  = security("BINANCE:AVAXUSDT", "240", TLchange())
c_s10 = security("BINANCE:LUNAUSDT", "240", TLchange())
c_s11 = security("BINANCE:ALGOUSDT", "240", TLchange())

c_scr_label  = "Screener: Traffic Lights (Change)" + "\n4H Chart" + "\nLong + Short Conditions" + "\n=========================="
c_scr_label := c_s1  ? c_scr_label + "\nBTCUSDT"  : c_scr_label 
c_scr_label := c_s2  ? c_scr_label + "\nETHUSDT"  : c_scr_label 
c_scr_label := c_s3  ? c_scr_label + "\nBNBUSDT"  : c_scr_label 
c_scr_label := c_s4  ? c_scr_label + "\nADAUSDT"  : c_scr_label 
c_scr_label := c_s5  ? c_scr_label + "\nLTCUSDT"  : c_scr_label 
c_scr_label := c_s6  ? c_scr_label + "\nBCHUSDT"  : c_scr_label 
c_scr_label := c_s7  ? c_scr_label + "\nLINKUSDT" : c_scr_label 
c_scr_label := c_s8  ? c_scr_label + "\nSOLUSDT"  : c_scr_label 
c_scr_label := c_s9  ? c_scr_label + "\nAVAXUSDT" : c_scr_label 
c_scr_label := c_s10 ? c_scr_label + "\nLUNAUSDT" : c_scr_label 
c_scr_label := c_s11 ? c_scr_label + "\nALGOSDT"  : c_scr_label 


c_label = label.new(bar_index, 0, c_scr_label,
                     color=color.new(color.lime, 0),
                     textcolor=color.new(color.white, 0))
label.delete(c_label[1])
















