Quick Answer
The Pine Script error "The script executes too many unique request.*() function calls" means that your script asks for more different datasets than your plan allows. The TradingView support page for this error gives two limits: 40 unique data requests on non-professional plans, and up to 64 on professional plans (it says Pine v6 scripts on those plans). The Pine limitations page gives the same numbers in short: 40 unique calls, or 64 on the Ultimate plan. Plan rules change, so check the current page for your plan.
The word that matters is unique. According to the support page, a call is unique by its symbol, its timeframe and modifiers, its expression, and the scope it runs from. The limitations page adds that repeated identical calls generally do not count: "only the first call usually counts toward this limit". So a loop that sends the same request.security() 50 times is fine, and a loop that changes the timeframe on every pass is not.
The fixes are to ask for fewer different things: remove symbols and timeframes you do not use, get several values from one symbol and timeframe in one call with a tuple, or split the work into two scripts. A fourth limit comes with tuples: all request.*() calls together cannot return more than 127 tuple elements. This post shows a broken script, the fixes, and what to do with this limit if you convert the script to MQL5 or cTrader C#. All scripts here are my own, and I have not run them in TradingView, so run them before you rely on them.
From the author: I convert multi-timeframe Pine scripts to MQL5. This error is a good hint for the conversion too: a script that asks for 40 datasets is a script that needs 40 indicator handles in MQL5, and that is a design problem before it is a syntax problem.
Key Facts
| Question | Answer from the TradingView pages |
|---|---|
| What is the limit? | 40 unique request.*() calls; 64 on professional plans (the support page says for Pine v6 scripts), 64 on Ultimate (limitations page) |
| What makes a call unique? | Symbol, timeframe and modifiers, expression, and scope (support page) |
| Do repeated identical calls count? | Generally no; "only the first call usually counts" (limitations page) |
| Does a loop count each pass? | Only if each pass is a different call, for example a different timeframe |
| Do library calls count? | Yes: calls inside imported library functions count even if the main script makes the same call |
| Is there a tuple limit? | Yes: all request.*() calls together cannot return more than 127 tuple elements |
| What does the support page suggest? | Upgrade to a professional plan, or rewrite the script to use fewer unique requests |
A Broken Script
This script asks for the daily close of forty-five different timeframe strings in a loop:
//@version=6
indicator("Too many requests")
float total = 0.0
for i = 1 to 45
total += request.security(syminfo.tickerid, str.tostring(i), close)
plot(total)
Each pass has another timeframe argument, so each pass is a different call. The Pine limitations page describes the same shape: a loop that repeats the same call 50 times does not hit the limit, and a loop in which each pass uses a different timeframe hits it, in its example at pass 41. In v6, dynamic requests (a series string timeframe) are on by default, which is why this compiles at all. I have not run my script, so check where it stops on your plan.
Fix 1: Ask for the Same Thing Once
If the same call appears many times, nothing is wrong. The limit counts the first one:
//@version=6
indicator("Same call, many times")
float total = 0.0
for i = 1 to 50
total += request.security(syminfo.tickerid, "D", close) // one unique call
plot(total)
Check your script for calls that look different but are the same: the same symbol, timeframe and expression written in two places. If you move them to one variable at the top of the script, the code is also easier to read.
Fix 2: One Call With a Tuple Instead of Many Calls
Different expressions on the same symbol and timeframe are different calls. Four calls for open, high, low and close are four unique requests:
//@version=6
indicator("Four calls", overlay = true)
o = request.security(syminfo.tickerid, "D", open)
h = request.security(syminfo.tickerid, "D", high)
l = request.security(syminfo.tickerid, "D", low)
c = request.security(syminfo.tickerid, "D", close)
Put the values in a tuple and you have one call:
//@version=6
indicator("One call", overlay = true)
[o, h, l, c] = request.security(syminfo.tickerid, "D", [open, high, low, close])
I could not confirm in the docs that the first version counts as four and the second as one, so test it: add calls one at a time and see where the error appears. The idea of requesting several values in one tuple comes from the Pine profiling page.
The 127 Tuple Element Limit
A tuple does not remove the limit, it moves it. The limitations page says that all the request.*() calls in a script, taken together, cannot return more than 127 tuple elements, and that splitting a tuple into several calls does not avoid it: two calls that each return 64 elements also fail. The page names the workaround: pack the values into a user-defined type (UDT) and request the UDT object. If your script needs more than a few dozen values from outside, that is the moment to ask whether it should be one script.
Fix 3: Fewer Symbols and Timeframes
The most common cause in real scripts is a watchlist:
//@version=6
indicator("Watchlist", overlay = false)
symbols = array.from("EURUSD", "GBPUSD", "USDJPY", "AUDUSD", "USDCAD", "NZDUSD")
float strength = 0.0
for s in symbols
strength += request.security(s, "D", ta.roc(close, 5))
plot(strength)
Six symbols are six unique calls, which is fine. Sixty are not. Options:
- Keep only the symbols that feed a decision (a symbol you never plot or test is a request you pay for).
- Split the list into two scripts and combine the result on the chart.
- Use a longer timeframe for a symbol if a coarse value is enough.
- If it is a timeframe grid, ask which timeframes you actually use. Often three or four are enough.
Fix 4: Check the Libraries You Import
The limitations page says that request.*() calls inside imported library functions count toward the limit, even if your main script makes the same call. A script with 25 calls of its own and a library with 20 more is at 45. If you cannot see the library code, remove the library and test the count again.
Related Errors in the Same Family
| Message | What it means | Where to look |
|---|---|---|
| Too many unique request.*() calls | More different datasets than the plan allows | This post |
| Memory limits exceeded (RE10139) | Too much data in memory, often from large request.*() data | Memory limits exceeded |
| Calculation takes too long to execute | The script runs for too long | Calculation takes too long |
| Compiled code contains too many tokens (CE10117) | The script is too large | Too many tokens |
| Historical offset beyond buffer limit (RE10143) | You look back too far | Historical offset error |
What to Check When You Convert the Script
A multi-timeframe Pine script is not the same size in MQL5 or C#:
| Pine | MQL5 | cTrader C# |
|---|---|---|
| One request.security() for another timeframe | One indicator handle for that timeframe, read with CopyBuffer() | MarketData.GetBars(timeFrame) and an indicator on those bars |
| A loop over 40 symbols | 40 handles in an array, with data that may not be ready on the first tick | 40 Bars objects and 40 indicators |
| A tuple of OHLC | CopyRates() or iOpen-style calls in one pass | The Bars object of that timeframe |
In MQL5 the handle for another symbol or timeframe may need a tick before its data is there (see the MQL5 CopyBuffer error 4806), so a 40-symbol scanner is a larger project than it looks in Pine. The post on request.security() in MQL5 shows the basic pattern for one extra timeframe.
Checklist: What to Check When You See This Error
- Count the
request.*()calls in your script, including those inside loops and functions. - Find calls that are the same and move them to one variable.
- Look for loops where the symbol or timeframe changes on every pass.
- Put values from the same symbol and timeframe into one tuple.
- Count the tuple elements, and use a UDT if you are near 127.
- Remove symbols and timeframes that do not feed a decision.
- Check imported libraries for
request.*()calls. - Check your plan's current limit on the TradingView pages.
- Compare the output of the old and the new script on a chart.
Common Mistakes
- Counting calls by lines and not by unique symbol, timeframe, expression and scope.
- Looping over timeframes to "scan" them all.
- Four calls for OHLC where one tuple is enough.
- Forgetting library calls.
- Using a UDT or a tuple to hide 200 values you do not need.
- Upgrading the plan before checking whether the script needs that many requests.
FAQ
Related Guides
- Pine Script request.security() in MQL5: one extra timeframe, step by step.
- Pine Script memory limits exceeded: when requests use too much memory.
- Pine Script calculation takes too long: the time limit and the Profiler.
- Pine Script compiled code contains too many tokens: when the script is too large.
- Pine Script historical offset beyond buffer limit: looking back too far.
- Pine Script v6 to MQL5: what changes between versions when you convert.
- MQL5 CopyBuffer error 4806: data for another timeframe that is not ready.
- Pine Script to MQL5 guide: converting a script step by step.
Convert Without Guessing
If you want a first draft of your Pine Script in MQL5 or cTrader C#, try the CodeFlowOS converter. It produces a draft that you still have to review, and the compiler check is optional. Outputs are not guaranteed, and code that compiles can still have wrong logic, so always compare the result with the chart. If the converted code does not compile, paste it with the message into the Error Fixer: it suggests a minimal fix and shows what changed (1 credit, with up to 3 attempts included).
This article is educational. It does not describe trading performance and is not financial advice. Test every script on a chart or a demo account before you rely on it.