line N: Script requesting too many securities. The limit is 40.Your script triggers more than the allowed number of unique request.security() data requests (40 on standard plans). Educational only — this reference explains the limit and how to consolidate requests; it makes no claim about profitability.
Each unique combination of symbol, timeframe, and requested expression that reaches request.security() counts toward the request quota. A single script can make at most 40 unique requests on standard plans (Pine v6 raises this to 64 on the Professional plans). Calling request.security() inside a loop, inside a function that is called many times, or across many symbols multiplies the count fast. Identical calls with identical arguments are de-duplicated into one request, but a call whose arguments vary (for example a loop index picking a different symbol each iteration) is counted separately every time.
Reduce the number of distinct request.security() calls. Move the calculation you need into the expression argument of request.security() (request the finished value, not raw price you then recompute per symbol), reuse a single requested tuple across downstream code instead of re-requesting, and pull requests out of loops. If you genuinely need many symbols, split the logic across multiple scripts so each stays under the quota. When you do request an intrabar-safe value, offset the series by [1] and pass barmerge.lookahead_off to avoid repainting.
//@version=6
indicator("Too many securities", overlay = true)
symbols = array.from("AAPL","MSFT","GOOG","AMZN","META","NVDA","TSLA","AMD","INTC","NFLX")
total = 0.0
// request.security() inside a loop over many symbols and timeframes
// blows past the 40-request limit
for tf in array.from("5","15","60","240","D")
for i = 0 to array.size(symbols) - 1
sym = array.get(symbols, i)
v = request.security(sym, tf, close)
total += v
plot(total)✓ Validated clean by our own engine
//@version=6
indicator("Consolidated request", overlay = true)
// One symbol input, one timeframe input -> a single unique request.
htfSym = input.symbol("AAPL", "Symbol")
htfTf = input.timeframe("D", "Higher timeframe")
len = input.int(20, "EMA length", minval = 1)
// Do the calculation INSIDE the request expression so you fetch the
// finished value once, offset by [1] with lookahead_off to avoid repainting.
htfEma = request.security(htfSym, htfTf, ta.ema(close, len)[1], lookahead = barmerge.lookahead_off)
plot(htfEma, "HTF EMA", color = color.orange)Educational, code-correctness reference only — not financial advice. Trading involves substantial risk of loss.