Edgoro
Runtime error · Runtime limits

Pine Script: Script requesting too many securities (fix)

Pine Script allows 40 unique request.*() calls per script (64 with Ultimate). How to cut requests with tuples and shared calls to fix the error.

Runtime error on the chart
Script requesting too many securities

Cause

The script makes more unique request.*() calls than allowed: 40 per script, or 64 with TradingView's Ultimate plan. Each different combination of symbol, timeframe and expression counts, including calls inside a function that you call several times.

Broken code

This script compiles, but stops on the chart with the error above.

Pine Script v6
//@version=6
indicator("Watchlist ratio")
// One request per value: 4 calls per symbol.
// The same pattern for 11 symbols makes 44 calls, over the limit of 40.
aaplClose = request.security("NASDAQ:AAPL", "D", close)
aaplHigh  = request.security("NASDAQ:AAPL", "D", high)
aaplLow   = request.security("NASDAQ:AAPL", "D", low)
aaplVol   = request.security("NASDAQ:AAPL", "D", volume)
msftClose = request.security("NASDAQ:MSFT", "D", close)
msftHigh  = request.security("NASDAQ:MSFT", "D", high)
msftLow   = request.security("NASDAQ:MSFT", "D", low)
msftVol   = request.security("NASDAQ:MSFT", "D", volume)
plot(aaplClose / msftClose)

Fixed code

The same script, corrected for Pine Script v6. Paste it into the Pine Editor and save.

Pine Script v6
//@version=6
indicator("Watchlist ratio")
// One request per symbol, returning all four values as a tuple.
[aaplClose, aaplHigh, aaplLow, aaplVol] = request.security("NASDAQ:AAPL", "D", [close, high, low, volume])
[msftClose, msftHigh, msftLow, msftVol] = request.security("NASDAQ:MSFT", "D", [close, high, low, volume])
plot(aaplClose / msftClose)

Why it works

One request.security() call can return several values at once as a tuple, so four calls per symbol become one: 11 symbols × 4 values drops from 44 calls to 11. The broken example is shortened to two symbols to stay readable; the error appears once the pattern passes the limit.

Other ways to cut requests

  • Calculate inside the request. [c, ma] = request.security(sym, "D", [close, ta.sma(close, 20)]) returns the close and its average in one call.
  • Reuse results. A call with exactly the same arguments as an earlier one is typically not unique and reuses its data, but storing the result in a variable and reusing it is clearer.
  • Watch functions. A function that wraps request.security() adds a call for each distinct set of arguments it is called with.
  • Split the script. A very large watchlist can be spread over two indicators.

The limit covers all request functions, including request.security_lower_tf(), request.financial() and request.economic(). A script's requests can return at most 127 tuple elements in total.

Questions

How many request.security() calls can a Pine Script make?

Up to 40 unique request.*() calls, or up to 64 if the user has TradingView's Ultimate plan, according to the Pine Script limitations page.

Do identical request.security() calls count twice?

Not typically. A call with the same arguments as an earlier one reuses its data. Store the result in a variable and reuse it to be sure.

The scripts on this page are minimal examples written to show the error and its fix, not trading systems. Trading involves substantial risk of loss and is not suitable for every investor. Edgoro is a software tool, not a broker or financial adviser: nothing it produces is investment advice, and past or backtested performance does not guarantee future results.

Still getting an error?

Paste your script and the message into the free Pine Script error fixer: it explains what went wrong and returns a corrected v6 version. Or describe the indicator in plain English and let Edgoro write the code.