TradingView
QuantNomad
May 19, 2021 7:36 PM

Custom Multi-Timeframe Screener with Alerts 

Tesla, Inc.NASDAQ

Description

This is a multi-timeframe screener with alerts. Use this way you can create a screener on indicators using 2 or more timeframes.
In TradingView there is a limit of 40 security function calls. Every timeframe requires another security call so you can screen fewer symbols with any additional timeframe.
In this example, I use 2 timeframes, so the maximum amount of symbols you can scan is 40/2 = 20.
For 3 timeframes - 13, 4tfs - 10, 5tfs - 8 symbols and so on.

In this simplistic example, I require a cross of EMAs on the current timeframe and confirmation that one EMA above/below another from the second timeframe.
Of course, you can create much more complicated functions for this screener.

Params
- higher timeframe
- ema params
- 20 symbol inputs for instruments you want to use in this screener

Alerts
You can create an alert from it easily by selecting the screener name from the list and then selecting "Any alert() function call".
No additional configuration is required, message and alert on close is generated in the code.
You should better change the default name for your alert. Sometimes because of big amount of inputs you might receive an error.

Disclaimer
Please remember that past performance may not be indicative of future results.
Due to various factors, including changing market conditions, the strategy may no longer perform as good as in historical backtesting.
This post and the script don’t provide any financial advice.
Comments
jntagara
This doesn't work,
I did not gent any of the alerts or po-pup's
Arpan_Eng
Since we can use only 20 companies after calling security function to get higher time frame data, I am trying to filter stocks sectorwise by selecting and changing sectors from settings
using 'input function'. But while trying to do so, getting different kinds of errors.

string varSector = input("Custom", "Sector Selection", inline = "11", options = ) ) // <<This comment section is automatically removing 'sector names' from options of input function so please consider different sectors as options

if varSector == "Auto"
s01 := input('Auto_stock1', type=input.symbol, group = "Symbols")
s02 := input(' Auto_stock2', type=input.symbol, group = "Symbols")
.
.
s20 := input(' Auto_stock20', type=input.symbol, group = "Symbols")

else if varSector == "Banks"
s01 := input('Bank_stock1', type=input.symbol, group = "Symbols")
s02 := input(' Bank_stock2', type=input.symbol, group = "Symbols")
.
.
s20 := input(' Bank_stock20', type=input.symbol, group = "Symbols")

//Calling screener function
= security(s01, timeframe.period, screenerFunc(h1,l1,pc1) )
= security(s02, timeframe.period, screenerFunc(h2,l2,pc2) )

It shows ‘Undeclared Identifier’ msg for s01, s02….s20 when I use them inside IF condition.If I declare them first and use, it shows ‘Cannot modify global variable 's01, s02..' in function’. Even tried to use those IF..Else conditions inside a function but it shows either ‘Undeclared Identifier’ or ‘Cannot use a mutable variable as an argument of the security function’. Can you please help me to resolve this issue?

Thanks
UnknownUnicorn2806273
Great Work! Thank you for sharing!
It seems the code is looking into the regular session only, How I can include extended session ?
Can someone point me the right direction please?
Much appreciated and thank you in advance :-)
wholdeman
Hello,

I am wanting to hire someone or work with someone to create a custom alert. Do you have any thoughts or suggestions on how to do this? I would like to combine MacD, moving averages, support/resistance on higher time frames to alert a buy or sell for the 1H, 5m and 1m time frames for a particular security. Please let me know if I should go to a website like Fivvr or if you have used someone in the past you would suggest.
KolaInvest2
Once you set the TV alert, do you need to keep this up on your chart as an indicator?
QuantNomad
@KolaInvest2, Nope,you can close it after alert creation.
Stypto_Algo
Hello sir, I am having trouble adding Keltner Channel into the HTF area in the line 51 area. It gives me a weird error with "=>" this symbol. I don't know what to do. And I really need it to work. Do you know how to add this so it can work in the higher time frame calculation?
mincho1010
Hi, I am trying to build an MTF screener with 2 rsi. I wrote the function like this but I get the error "Syntax error: Variables of array type are not supported!"

The error appears on this line:

j01 = c01 == 1 and ch01 == 1 ? 1 : c01 == -1 and ch01 == -1 ? -1 : 0

Here is the code snippet:

///////////////
// FUNCTIONS //

// Rounding Function
roundn(x, n) =>
mult = 1
if n != 0
for i = 1 to abs(n)
mult := mult * 10

n >= 0 ? round(x * mult) / mult : round(x / mult) * mult

screenerFunc() =>

rsiL = rsii >= Ob
rsiS = rsii <= Ov
value = rsii

long = rsiL
short = rsiS

cond1 = long ? 1 : short ? -1 :0

L= cond1[1] < 1 and cond1 >= 1
S= cond1[1] > -1 and cond1 <= -1

cond = L ? 1 :
S ? -1 :
na

[value, cond]

screenerFuncHTF() =>

rsiL1 = rsii1 >= Overbought
rsiS1 = rsii1 <= Oversold
value1 = rsii1

cond2 = rsiL1 ? 1 : rsiS1 ? -1 :0

[value1, cond2]
ahmar91
why i am not getting alerts when EMA cross happen for long strategy. I want separate alert for each pair when EMA cross happened. Anyone can please look into where i am wrong, why my alert script is not working

//@version=4
strategy("Alerts for Multipairs EMA Cross", shorttitle = 'EMA Cross alert', overlay = false)

// INPUTS //

fastemalength = input(title="Fast EMA", type=input.integer, defval=8)
slowemalength = input(title="Slow EMA", type=input.integer, defval=21)

// Screener Function
screenerFunc() =>

emafast = ema(close, fastemalength)
emaslow = ema(close, slowemalength)

long = emafast > emaslow

// Running Functions for all sybmols //

s1 = security('BTCUSDT', timeframe.period, screenerFunc())
s2 = security('ETHUSDT', timeframe.period, screenerFunc())
s3 = security('BNBUSDT', timeframe.period, screenerFunc())
s4 = security('LTCUSDT', timeframe.period, screenerFunc())
s5 = security('ADAUSDT',timeframe.period, screenerFunc())
s6 = security('UNIUSDT', timeframe.period, screenerFunc())
s7 = security('ATOMUSDT',timeframe.period, screenerFunc())
s8 = security('BATUSDT', timeframe.period, screenerFunc())
s9 = security('RUNEUSDT',timeframe.period, screenerFunc())

// Screener label //

scr_label = 'Screener: \n##########\n'

scr_label := s1 ? scr_label + 'BTCUSDT\n' : scr_label
scr_label := s2 ? scr_label + 'ETHUSDT\n' : scr_label
scr_label := s3 ? scr_label + 'BNBUSDT\n' : scr_label
scr_label := s4 ? scr_label + 'LTCUSD\n' : scr_label
scr_label := s5 ? scr_label + 'ADAUSDT\n' : scr_label
scr_label := s6 ? scr_label + 'UNIUSDT\n' : scr_label
scr_label := s7 ? scr_label + 'ATOMUSDT\n' : scr_label
scr_label := s8 ? scr_label + 'BATUSDT\n' : scr_label
scr_label := s9 ? scr_label + 'RUNEUSDT\n' : scr_label

lab_l = label.new(
bar_index, 0, scr_label,
color=color.gray,
textcolor=color.black,
style = label.style_labeldown,
yloc = yloc.price)
// This will keep screener only for the last bar
label.delete(lab_l[1])

//Long Strategy when emafast > emaslow

strategy.entry("Long",strategy.long, when = s1, alert_message = "USDT_BTC Alert")
strategy.entry("Long",strategy.long, when = s2, alert_message = "USDT_ETH Alert")
strategy.entry("Long",strategy.long, when = s3, alert_message = "USDT_BNB Alert")
strategy.entry("Long",strategy.long, when = s4, alert_message = "USDT_LTC Alert")
strategy.entry("Long",strategy.long, when = s5, alert_message = "USDT_ADA Alert")
strategy.entry("Long",strategy.long, when = s6, alert_message = "USDT_UNI Alert")
strategy.entry("Long",strategy.long, when = s7, alert_message = "USDT_ATOM Alert")
strategy.entry("Long",strategy.long, when = s8, alert_message = "USDT_BAT Alert")
strategy.entry("Long",strategy.long, when = s9, alert_message = "USDT_RUNE Alert")
UnknownUnicorn10087866
hi
your excellent work has helped me a lot to understand pine script.I am not so expert to pine coding.
Hi, can you please help me to modify this script. i want to create a lists based on price action strategy or VWAP and WMA crossover/crossunder.
I want to create two different lists based on price action or VWAP and WMA crossover/crossunder like (1) BULLISH (2) BEARISH.
Please guide which part to modify and what to add. For example I have two symbols NSE:ADANIPORTS1! and NSE:ASIANPAINT1!
Please guide and help

Thanks
More