Custom Multi-Timeframe Screener with Alerts

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.

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

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.

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.

本着真正的TradingView精神,该脚本的作者将其开源发布,因此交易者可以理解和验证它。为作者加油! 您可以免费使用它,但是在发布中重复使用此代码受网站规则的约束。您可以收藏它以在图表上使用。

Pine Programming: https://qntly.com/pineprog
Advanc. Pine Use-Cases: https://qntly.com/advpine

Access to Pro Indic.: https://qntly.com/proind

YouTube: https://qntly.com/youtube
Discord: https://qntly.com/discord
Telegram: https://qntly.com/tel


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?

+2 回复
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:


// 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 and cond1 >= 1
S= cond1 > -1 and cond1 <= -1

cond = L ? 1 :
S ? -1 :

screenerFuncHTF() =>

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

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

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

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,
style = label.style_labeldown,
yloc = yloc.price)
// This will keep screener only for the last bar

//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")
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

... maximum number of symbols...
Thanks a lot for this. I want to do the following but am not sure how and if this can be done. could you please help. I want to look at 8 symbols and an alert when they are above the EMA(9) on the 5 min, 10 min, 30 min, 60 min and the alert must be triggered when it crosses the EMA(9) on the 240 min i.e. 4h time frame. Is this doable?
QuantNomad tugga82
@tugga82, So cross on higher timeframe and above EMA on lower timeframes?
It's possible. Create one function for cross (like screenerFunc in my code), calculate it for 240m timeframe. Create a function for above EMA (like screenerFuncHTF in my code), compute it for all other timeframes. Join all 5 condition together with "and" operator like I do for "j01-j20" vars.
tugga82 QuantNomad
@QuantNomad, yes cross on higher timeframe and above EMA on lower timeframes? I shall try this based on what you are suggesting and see if it works. Will keep you posted. Thanks for everything that you do. Cheers,
@tugga82, Hello I am also looking for same kind of alert. Could you please send me the source code if it worked for you. Thanks in advance
tugga82 deekshith6494
@deekshith6494, No I couldnt get this to work