Skip to main content

TradingView Custom Screener Script: From Zero to Pro

· 9 min read

Learn to build a custom TradingView screener script with Pine Script. Master multi-symbol scanning, alert automation, and performance optimization for stock, crypto, and forex trading strategies.

TradingView Custom Screener Script: From Zero to Pro

Why build your own TradingView screener script?

TradingView's built-in screeners for stocks, crypto, and forex are super handy to get started. But after a while, you might find they can't do a few key things that matter for a more personalized strategy:

  • Bake in your own secret sauce: They can't use your unique indicator logic or that special combination of factors you've been tweaking.
  • Check multiple timeframes at once: What if you want to see a daily trend confirming a 1-hour setup? The standard screeners can't run those conditions together in real-time.
  • Connect to your other tools: They don't naturally send alerts to your Discord, Slack, or connect directly to an automated trading system.

That's where writing your own Pine Script screener comes in. It lets you turn your specific strategy into code, pull in data from other symbols using request.security(), and set up alerts that can ping you on your favorite platforms or even talk to a trading bot. It's basically about building a tool that works exactly the way you do.

Core ingredients

Here's a breakdown of the essential building blocks you have to work with, and the practical limits you need to keep in mind to keep your script running smoothly.

IngredientPurposeKey limits
request.security()Pull OHLCV or series from another symbol / timeframe40 symbols per bar
ta.xxx() functionsApply built-in TA like SMA, RSI, ATRSame as regular Pine
Table objects (table.new)Render screener hits on-chartUp to 100 cells visible
Alerts (alertcondition)Fire once or each bar for matched tickersSame 40-symbol ceiling
input.symbol() arraysLet users choose portfolios250 inputs max per script

Step-by-step build guide

1. Draft screening logic

Start by setting up clear true/false conditions. Here's what I mean:

// Price above 200-EMA AND 14-period RSI oversold
longCond(sym) =>
close > ta.ema(request.security(sym, timeframe.period, close), 200) and
ta.rsi(request.security(sym, timeframe.period, close), 14) < 30

Try to keep your helper functions simple and focused - don't put plot() inside them so they stay easy to work with.

2. Collect symbols

Most people type out their favorite stocks directly in the settings:

// Comma-separated list in settings
syms = str.split(input.string("AAPL,MSFT,NVDA,AMZN,META"), ",")

If you're feeling adventurous, you might eventually use watchlists through array.get() once that feature becomes more widely available (looks like around October 2025).

3. Evaluate conditions

Now check each symbol in your list:

hits = ""
for s in syms
if longCond(s)
hits := hits + s + ", "

Keep an eye on your loop counts - you don't want to hit that 50,000 operations limit.

4. Display results

Show everything in a clean table:

if barstate.islast
tbl = table.new(position.top_right, 1, 1)
table.cell(tbl, 0, 0, text=hits == "" ? "No setups" : hits)

This way you can quickly see what's working right from your chart.

5. Create alerts

Set up one alert to catch everything:

alertcondition(barstate.isconfirmed and hits != "", title="Screener Hit",
message="⚡️ Screener triggered: {{ticker}} {{interval}}")

If you save this as "once per bar," you'll get a neat list of all the symbols that matched your criteria.


Simple Tricks to Keep Your Scripts Running Smoothly

When you're building scripts, especially ones that pull a lot of data, they can sometimes get slow or hit limits. Here are a few straightforward ways I've found to keep everything running quickly and reliably.

TacticWhat It DoesWhy It Helps
Split ExchangesInstead of one script trying to load 80 symbols, you create two or three smaller scripts (e.g., one for symbols 1-40, another for 41-80).It neatly avoids the hard limit many data sources have on how many symbols you can request at once.
Load-BalancingYou stagger the timeframes your scripts use. For instance, have one script on a 15-minute chart, another on a 1-hour chart, and a third on a daily chart.This spreads out the processing load over time instead of having everything calculate at once, which keeps the runtime low.
Use Lightweight MathDo your heavy calculations once and store the result, rather than recalculating the same thing over and over inside a loop.It's a simple programming habit that saves a surprising amount of processing power.
Avoid security() RecursionNever, ever nest a request.security() call inside another request.security() call.This creates a dependency loop that can cause timeouts or errors, and it's almost always the wrong approach.

Implementing these optimizations manually can be a meticulous task. For traders who want to focus more on strategy and less on code debugging, a tool like Pineify can be a game-changer. Its visual editor allows you to build and manage complex indicators and strategies without writing a single line of code, automatically generating efficient and error-free Pine Script.

Pineify Website

This means you can apply principles like load-balancing and creating multi-symbol screeners with just a few clicks, saving you the time and frustration of manual coding.

Making Your Script Work for You: Compliance & Monetization

So you've built a great TradingView script. Here are a few straightforward ways to share it responsibly and even earn from your work.

  1. Exclusive Access for Subscribers: Instead of making your script public, you can publish it as a protected, invite-only tool. This lets you build a community of subscribers and collect recurring revenue, all while keeping your code secure.

  2. Streamlined Onboarding for Users: TradingView has a great feature that lets you bundle your script with a custom chart setup or screener preset into a single, shareable link. This is a game-changer for your users because it gets them up and running in just one click, saving them the hassle of manual configuration.

  3. Automate Your Trading Workflow: For a more advanced setup, you can connect your script to automation platforms like Zapier or a custom AWS Lambda function using webhooks. This can automatically size and place orders with a connected broker, turning your strategy into a hands-free system.

Troubleshooting Common Pine Screener Issues

Here's a quick guide to some common problems you might run into and how to fix them.

SymptomCauseFix
"Too many security calls"> 40 symbolsSplit portfolio
Table overlaps UITable size dynamicPin to position.top_right
Alert payload emptyhits resets each loopAppend only on last bar

Q: If I move to another browser tab, will my Pine Screener alerts still run? A: Absolutely. Once you've set an alert, it's handled on our servers and runs around the clock, even if you close your browser completely.

Q: Can I use the screener on a free plan? A: Yes, you can. The main limitation is that free plans allow only one server-side alert, which restricts how much you can automate.

Q: What's the best way to add fundamental data, like the P/E ratio? A: You can access that data in Pine Script using the financial() namespace. Just remember, these calls still count toward the 40-symbol limit, so you'll need to keep an eye on your total.

Where to go from here

Alright, you've got the blueprint. Here's how to make it your own and actually put it to work.

  1. Start by copying the code skeleton we just went through directly into your Pine Editor. That's your foundation.
  2. This is the fun part: Swap out the generic longCond() placeholder with your own secret sauce. Think about what gets you excited:
    • A MACD crossover signaling a shift in momentum.
    • A stock bouncing decisively off the VWAP.
    • That specific RSI level that has worked for you in the past.
    • Whatever your unique edge is, that's what goes here. For more advanced technical analysis, you might explore using the ta.linreg() function to incorporate linear regression into your screening conditions.
  3. Don't just throw 500 tickers into one list. It's messy and hard to manage. Instead, split your big watchlist into smaller, logical groups. You could have one for high-momentum tech stocks, another for stable ETFs, and a third for volatile small-caps, for example. It makes everything so much clearer.
  4. Test everything before you rely on it. Create a separate screener for each of your mini watchlists and run a backtest. See how your logic holds up. Once you're confident, set up your alerts and connect them to a webhook (like Discord or Telegram) so the signals come straight to you. If you're looking for proven indicators to test, check out our guide on the best free TradingView indicators for 2025.
  5. Built something cool? Share it. You can simply send your setup link to a friend, or if you've created a real powerhouse, you can publish it as an invite-only indicator on TradingView. It's a great way to build a community or even earn a little from your most dedicated followers. For traders looking to enhance their analysis with volume-backed trends, consider incorporating the Elastic Volume Weighted Moving Average into your screening conditions.

When building complex screeners, you might find that multi-timeframe analysis becomes essential for confirming signals across different time horizons.