Pine Script Limits: 64 Plots, 40 Requests, 500 ms Loops
Your script ran fine yesterday and now throws a limit error. Here are the Pine Script caps that bite traders: plots, request calls, loops, buffers, orders.

You add one more plot to your indicator, save it, and the chart answers with a red error about a number you never agreed to. Or worse, the script loads clean, runs for two weeks, and dies on the first live tick of a Monday. Those errors are
You add one more plot to your indicator, save it, and the chart answers with a red error about a number you never agreed to. Or worse, the script loads clean, runs for two weeks, and dies on the first live tick of a Monday.
Those errors are not bugs. Pine Script runs on TradingView's cloud with hard caps on plots, data requests, loop time, history depth and trade count, and most of them can be designed around once you know the numbers.
Every number below comes from TradingView's Pine Script v6 Limitations page, which we read on 2026-11-27. TradingView can change these, so treat the docs as the source of truth and this post as the translation.
Plot counts are a budget, and alerts spend from it
The cap is 64 plot counts per script. The word "counts" matters, because a single call can cost up to seven.
The docs list what spends from the budget: plot(), plotarrow(), plotbar(), plotcandle(), plotchar(), plotshape(), bgcolor(), barcolor(), alertcondition(), and fill() when its color is a series (a value that changes bar by bar). What does not count: hline(), line.new(), label.new(), box.new() and table.new().
The docs give an example that adds up to 56 counts. Add two more plotcandle() calls and it jumps to 70, because each of those costs seven: 56 plus 7 times 2. The runtime error tells you the total, and the docs' method for finding the expensive line is blunt. Comment out one call at a time and watch the number fall.
The sneaky one for traders is alertcondition(). If you wrote a dashboard indicator with a dozen alert conditions for different setups, they eat the same budget as your moving averages.
The 40-request cap is about unique datasets, not call count
A script can make up to 40 unique calls to the request.*() functions, or up to 64 on the Ultimate plan. That covers request.security(), request.security_lower_tf(), request.currency_rate(), request.dividends(), request.splits(), request.earnings(), request.economic(), request.financial() and the rest of the namespace.
"Unique" is the key. The docs show a loop calling request.security() 50 times with identical arguments, and it runs fine, because repeats reuse the first call's data. Change the timeframe argument on every iteration and the same loop dies at iteration 41.
Two details catch people. Calls inside functions from an imported library do count, even if your main script already makes the identical request. And request.footprint() has its own rule: only one unique call, and only on Premium or Ultimate. We went through what that function returns in the footprint data post.
If you want a multi-symbol scanner, this is the cap you meet first. Thirty-odd symbols with two timeframes each is already over the line. Our opinion: when a script needs more than a dozen distinct requests, it is probably two scripts.
A loop has 500 ms per bar, and the whole run has a clock too
Any single loop on any single bar is limited to 500 milliseconds. Nested loops count as one, and the outer one times out first.
The trap is the second clock. The docs give the arithmetic themselves: a loop that takes 400 ms per bar passes the per-bar limit, but across a 20,000-bar dataset it would need 8,000 seconds. The total execution time allowed depends on your plan, and TradingView sends you to its pricing page for those figures, so we are not quoting them.
The docs also say there is currently no way for a Pine programmer to read how many resources a script is using. Their advice for big projects is to build a proof of concept first. We agree: write the heaviest part of the idea alone, run it on the full history, and only then build the rest around it.
The error that waits for the first live tick
Pine saves each variable's past values in fixed-size historical buffers (the memory behind the [] operator, as in close[500]). On historical bars, the runtime sizes those buffers automatically to what the script actually references.
Here is the catch from TradingView's historical buffer error page: the system does not keep resizing buffers after the script loads. A script that looks 500 bars back on history, then tries to look 1,000 bars back only on realtime bars, loads fine and raises a runtime error the moment a new tick arrives. The docs say you can reproduce it in Bar Replay by pressing Forward once.
The fix is max_bars_back(close, 1000) for the one series, or the max_bars_back parameter in indicator() or strategy() for all of them. The docs warn that oversized buffers cost memory and can push a script into its memory limit, so set the smallest size the script needs. The ceiling for most series is 5,000 bars back. The built-ins open, high, low, close and time reach 10,000.
— The Tradoki desk noteAn indicator that only works on closed history has not been tested. It has been looked at.
If you replay old data to test your logic, read our notes on how far back Bar Replay actually goes. It is a useful way to trigger a live-bar error on purpose.
Drawings, bars and orders each have their own ceiling
Three smaller limits explain a lot of "my chart looks wrong" questions.
Drawings. By default a script shows only the last 50 lines, boxes, polylines and labels. Raise it with max_lines_count, max_boxes_count, max_polylines_count or max_labels_count. A drawing set to na still counts toward the total, so a script that creates two labels per bar and blanks one of them shows fewer than you set. Drawings placed by bar index can sit at most 10,000 bars in the past and 500 bars in the future.
Chart bars. How much history you can load depends on your plan. The docs list a minimum of 5,000 bars on the lowest plans, 10,000 on Essential and Plus, 20,000 on Premium, 25,000 on Expert and 40,000 on Ultimate, when the data exists. A 5-minute chart and a daily chart hit very different calendar ranges at the same bar count. That is one reason two traders can backtest the "same" idea and see different histories.
Backtest orders. A strategy can place at most 9,000 orders in a backtest. Past that, the earliest orders are trimmed to store new ones, and strategy.closedtrades.first_index tells you where the surviving list starts. Deep Backtesting lifts the cap to 1,000,000. If your fast strategy shows a suspiciously short trade list, check this before blaming the data. For the other reasons tester results mislead, see why your TradingView strategy tester lies to you.
A pre-flight check before you ship a script
Run through this list when you build, and again when you hand a script to a friend on a cheaper plan.
- Count your plot spending. Sum the counts, with seven for the expensive candle calls, and leave headroom. Alerts are in the same budget.
- List your unique requests. Same arguments means one request. Different timeframe or symbol means a new one. Count library calls too.
- Time the heaviest loop on the full history, not on the last 500 bars.
- Test on a live bar. Leave the chart open through a few ticks, or press Forward in Bar Replay, before you trust a deep
[]reference. - Check the plan. Request caps, bar counts and total run time differ by subscription, so a script that works on your Ultimate account can fail on someone else's.
- Re-test after a version bump. Limits are not the only thing that moves. We covered the silent behavior changes in Pine Script v6 breaking changes.
If an AI assistant wrote part of the script, none of these caps will be in its head. Add them to your spec, as in our guide to writing Pine Script with Claude and GPT.
● FAQ
- Why does my Pine Script say I have too many plots when I only call plot a few times?
- The cap is 64 plot counts, not 64 plot() calls. Besides plot(), functions like plotshape(), plotchar(), bgcolor(), barcolor(), alertcondition() and a series-colored fill() all add to the count, and one call can add up to seven. TradingView's docs say the runtime error shows your actual count, and commenting out lines one at a time reveals which call costs what.
- How many request.security calls can one Pine Script use?
- Up to 40 unique calls to the request.*() functions, or 64 on the Ultimate plan, per TradingView's Limitations page. Identical calls with the same arguments reuse the first call's data and usually do not count again. Calls inside imported library functions do count, even if your main code makes the same request.
- Why did my indicator work on history and then crash on a live bar?
- Most likely a historical buffer error. Pine sizes the buffers for past values automatically on historical bars and stops resizing once the script loads, so a reference reaching deeper into history on realtime bars can raise a runtime error. The docs show the same error appearing after pressing Forward once in Bar Replay. A max_bars_back() call fixes it.
- Why do I only see the last 50 labels or lines from my script?
- By default a script keeps only the last 50 lines, boxes, polylines and labels on the chart. You can raise each cap with max_lines_count, max_boxes_count, max_polylines_count or max_labels_count in the indicator() or strategy() declaration. Drawings whose coordinates were set to na still count toward the total, which makes the visible number even smaller.
- Is there a cap on how many trades a Pine strategy can show in the backtest?
- A script can place a maximum of 9,000 orders when backtesting, and once it hits that, the earliest orders are trimmed to make room for new ones. Deep Backtesting raises the limit to 1,000,000. If your strategy trades often on a low timeframe, the early part of the history may simply not be in the list.
Three more from the log.

TradingView Strategy Fills at Next Bar Open, Not the Close
Pine strategies signal on the close but fill at the next open. See what process_orders_on_close changes and why 'On order fill' fakes exact-high exits.
Nov 21, 2026 · 7 min
Pine Script v6 Breaking Changes: 5/2 Now Returns 2.5
v5 to v6 compiles clean but changes your results: 5/2 now returns 2.5, and/or short-circuit, and default margin flips from 0% to 100%.
Sep 07, 2026 · 8 min
Why your TradingView strategy tester lies to you
Your equity curve looks perfect because a broker emulator guessed the inside of every candle. The documented assumptions that inflate a backtest.
Aug 12, 2026 · 9 min