5 Symbol screener with triple MA and RSI
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Lenny_Kiruthu

//@version=5
indicator(title="5 Symbol Forex with triple MA and RSI", shorttitle=" Triple MA and RSI Screener", overlay=true)

// USER INPUTS.
MA1Length = input.int(defval=21, title="MA1 Length", group="Moving Average Settings")
MA2Length = input.int(defval=50, title="MA2 Length", group="Moving Average Settings")
MA3Length = input.int(defval=200, title="MA3 Length", group="Moving Average Settings")

MA1Type = input.string(title="MA1 Type", defval="SMA", options=["RMA", "SMA", "EMA", "WMA"], group="Moving Average Settings")
MA2Type = input.string(title="MA2 Type", defval="SMA", options=["RMA", "SMA", "EMA", "WMA"], group="Moving Average Settings")
MA3Type = input.string(title="MA3 Type", defval="SMA", options=["RMA", "SMA", "EMA", "WMA"], group="Moving Average Settings")

MA1Source =input.source(title="MA1 Source", defval=close, group="Moving Average Settings")
MA2Source =input.source(title="MA1 Source", defval=close, group="Moving Average Settings")
MA3Source =input.source(title="MA1 Source", defval=close, group="Moving Average Settings")

MA1Timeframe = input.timeframe(title="MA1 Timeframe", defval="D", group="Moving Average Settings")
MA2Timeframe = input.timeframe(title="MA2 Timeframe", defval="D", group="Moving Average Settings")
MA3Timeframe = input.timeframe(title="MA3 Timeframe", defval="D", group="Moving Average Settings")

RSILength = input.int(defval=14, title="RSI Length", group="RSI Settings")
RSISource = input.source(defval=close, title="RSI Source", group="RSI Settings")
RSIOB = input.int(defval=70, title="RSI Overbought", group="RSI Settings")
RSIOS = input.int(defval=30, title="RSI Oversold", group="RSI Settings")
RSITimeframe = input.timeframe(defval="D", title="RSI Timeframe", group="RSI Settings")

s01 = input.symbol("AUDUSD", group="Symbols")
s02 = input.symbol("AUDJPY", group="Symbols")
s03 = input.symbol("GBPUSD", group="Symbols")
s04 = input.symbol("GBPJPY", group="Symbols")
s05 = input.symbol("USDCAD", group="Symbols")

// ma# is a variable used to store the actual moving average, once a user chooses a specific MA this code is run
ma1 = switch MA1Type
    "RMA" => ta.rma(MA1Source,MA1Length)
    "SMA" => ta.sma(MA1Source,MA1Length)
    "EMA" => ta.ema(MA1Source,MA1Length)
    "WMA" => ta.wma(MA1Source,MA1Length)
    
ma2 = switch MA2Type
    "RMA" => ta.rma(MA2Source,MA2Length)
    "SMA" => ta.sma(MA2Source,MA2Length)
    "EMA" => ta.ema(MA2Source,MA2Length)
    "WMA" => ta.wma(MA2Source,MA2Length)

ma3 = switch MA3Type
    "RMA" => ta.rma(MA3Source,MA3Length)
    "SMA" => ta.sma(MA3Source,MA3Length)
    "EMA" => ta.ema(MA3Source,MA3Length)
    "WMA" => ta.wma(MA3Source,MA3Length)


// Creating the function that calls from the daily timeframe and reads the first MA.
myScreener1(forex) =>

    Close = request.security(forex, MA1Timeframe, close[0])
    sma = ta.sma(MA1Source, MA1Length)
    sma_htf = request.security(forex, MA1Timeframe, sma[0])
    
    Close > sma_htf ? "Yes" : "No" 
    
    
// Creating the function that calls from the daily timeframe and reads the second MA.
myScreener2(forex) =>

    Close = request.security(forex, MA2Timeframe, close[0])
    sma = ta.sma(MA2Source, MA2Length)
    sma_htf = request.security(forex, MA2Timeframe, sma[0])
    
    Close > sma_htf ? "Yes" : "No" 
    
// Creating the function that calls from the daily timeframe and reads the third MA.
myScreener3(forex) =>

    Close = request.security(forex, MA3Timeframe, close[0])
    sma = ta.sma(MA3Source, MA3Length)
    sma_htf = request.security(forex, MA3Timeframe, sma[0])
    
    Close > sma_htf ? "Yes" : "No"   
    
// Creating the function that calls from the daily timeframe and reads the RSI.
myScreener4(forex) =>

    Close = request.security(forex, RSITimeframe, close[0])
    rsi = ta.rsi(RSISource, RSILength)
    rsi_htf = request.security(forex, RSITimeframe, rsi[0])
    
    math.round(rsi_htf) 
    
// Definig the back ground colors for the cells in the table
myBackground1(forex) =>    
    Close = request.security(forex, MA1Timeframe, close[0])
    sma = ta.sma(MA1Source, MA1Length)
    sma_htf = request.security(forex, MA1Timeframe, sma[0])
    
    MA1Color = Close > sma_htf ? color.green : color.red

myBackground2(forex) =>    
    Close = request.security(forex, MA2Timeframe, close[0])
    sma = ta.sma(MA2Source, MA2Length)
    sma_htf = request.security(forex, MA2Timeframe, sma[0])
    
    MA2Color = Close > sma_htf ? color.green : color.red
    
myBackground3(forex) =>    
    Close = request.security(forex, MA3Timeframe, close[0])
    sma = ta.sma(MA3Source, MA3Length)
    sma_htf = request.security(forex, MA3Timeframe, sma[0])
    
    MA3Color = Close > sma_htf ? color.green : color.red
    
myBackground4(forex) =>    
    Close = request.security(forex, MA3Timeframe, close[0])
    rsi = ta.rsi(RSISource, RSILength)
    rsi_htf = request.security(forex, RSITimeframe, rsi[0])
    
    rsi_htf > RSIOB ? color.red : rsi_htf < RSIOS ? color.green : color.gray
    

// Creating the table where all the indicators created in the functions will display the outcomes.
var myTable = table.new(position=position.top_right, columns=5, rows=11, bgcolor=color.black, border_width=1, frame_color=color.white, frame_width=4, border_color=color.white)

table.cell(table_id=myTable, column=0, row=0, text="FOREX",  text_color=color.white, bgcolor=color.gray)
table.cell(table_id=myTable, column=0, row=1, text=s01, text_color=color.white, bgcolor=color.gray)
table.cell(table_id=myTable, column=0, row=2, text=s02, text_color=color.white, bgcolor=color.gray)
table.cell(table_id=myTable, column=0, row=3, text=s03, text_color=color.white, bgcolor=color.gray)
table.cell(table_id=myTable, column=0, row=4, text=s04, text_color=color.white, bgcolor=color.gray)
table.cell(table_id=myTable, column=0, row=5, text=s05, text_color=color.white, bgcolor=color.gray)

table.cell(table_id=myTable, column=1, row=0, text="Currency pair above the " +str.tostring(MA1Length)+ " \nperiod " +str.tostring(MA1Type), text_color=color.white, text_halign=text.align_left)
table.cell(table_id=myTable, column=1, row=1, text=str.tostring((myScreener1(s01))), text_color=color.white, bgcolor=myBackground1(s01))
table.cell(table_id=myTable, column=1, row=2, text=str.tostring((myScreener1(s02))), text_color=color.white, bgcolor=myBackground1(s02))
table.cell(table_id=myTable, column=1, row=3, text=str.tostring((myScreener1(s03))), text_color=color.white, bgcolor=myBackground1(s03))
table.cell(table_id=myTable, column=1, row=4, text=str.tostring((myScreener1(s04))), text_color=color.white, bgcolor=myBackground1(s04))
table.cell(table_id=myTable, column=1, row=5, text=str.tostring((myScreener1(s05))), text_color=color.white, bgcolor=myBackground1(s05))

table.cell(table_id=myTable, column=2, row=0, text="Currency pair above the " +str.tostring(MA2Length)+ " \nperiod " +str.tostring(MA2Type), text_color=color.white, text_halign=text.align_left)
table.cell(table_id=myTable, column=2, row=1, text=str.tostring((myScreener2(s01))), text_color=color.white, bgcolor=myBackground2(s01))
table.cell(table_id=myTable, column=2, row=2, text=str.tostring((myScreener2(s02))), text_color=color.white, bgcolor=myBackground2(s02))
table.cell(table_id=myTable, column=2, row=3, text=str.tostring((myScreener2(s03))), text_color=color.white, bgcolor=myBackground2(s03))
table.cell(table_id=myTable, column=2, row=4, text=str.tostring((myScreener2(s04))), text_color=color.white, bgcolor=myBackground2(s04))
table.cell(table_id=myTable, column=2, row=5, text=str.tostring((myScreener2(s05))), text_color=color.white, bgcolor=myBackground2(s05))

table.cell(table_id=myTable, column=3, row=0, text="Currency pair above the " +str.tostring(MA3Length)+ " \nperiod " +str.tostring(MA3Type), text_color=color.white, text_halign=text.align_left)
table.cell(table_id=myTable, column=3, row=1, text=str.tostring((myScreener3(s01))), text_color=color.white, bgcolor=myBackground3(s01))
table.cell(table_id=myTable, column=3, row=2, text=str.tostring((myScreener3(s02))), text_color=color.white, bgcolor=myBackground3(s02))
table.cell(table_id=myTable, column=3, row=3, text=str.tostring((myScreener3(s03))), text_color=color.white, bgcolor=myBackground3(s03))
table.cell(table_id=myTable, column=3, row=4, text=str.tostring((myScreener3(s04))), text_color=color.white, bgcolor=myBackground3(s04))
table.cell(table_id=myTable, column=3, row=5, text=str.tostring((myScreener3(s05))), text_color=color.white, bgcolor=myBackground3(s05))

table.cell(table_id=myTable, column=4, row=0, text="Currency pair value on the RSI", text_color=color.white)
table.cell(table_id=myTable, column=4, row=1, text=str.tostring((myScreener4(s01))), text_color=color.white, bgcolor=myBackground4(s01))
table.cell(table_id=myTable, column=4, row=2, text=str.tostring((myScreener4(s02))), text_color=color.white, bgcolor=myBackground4(s02))
table.cell(table_id=myTable, column=4, row=3, text=str.tostring((myScreener4(s03))), text_color=color.white, bgcolor=myBackground4(s03))
table.cell(table_id=myTable, column=4, row=4, text=str.tostring((myScreener4(s04))), text_color=color.white, bgcolor=myBackground4(s04))
table.cell(table_id=myTable, column=4, row=5, text=str.tostring((myScreener4(s05))), text_color=color.white, bgcolor=myBackground4(s05))