Resource limit

Fix too many Pine Script drawings

Reuse or delete drawing IDs to control object growth. Pine limits both displayed drawings and available IDs. The fixed script creates one label with `var` and updates it on the last bar. This replaces historical annotations with a current status label, so use it only when that output meets your needs. Increase declaration limits only when more retained drawings are required; those limits do not remove the ID caps.

This link opens the Pine Script AI Coding Agent overview. It does not run or change code on this page.

Before and after

Make the smallest reviewable change

Both artifacts include the version declaration and the code needed to inspect the stated problem. The diff lists the lines that change between them.

Broken code.pine
//@version=6
indicator("Drawing limit demo", overlay = true)
label.new(bar_index, high, str.tostring(high))
Fixed code.pine
//@version=6
indicator("Drawing limit demo", overlay = true)
var label status = label.new(na, na, "")
if barstate.islast
    label.set_xy(status, bar_index, high)
    label.set_text(status, str.tostring(high))
Diff.pine
--- broken.pine
+++ fixed.pine
@@
-label.new(bar_index, high, str.tostring(high))
+var label status = label.new(na, na, "")
+if barstate.islast
+    label.set_xy(status, bar_index, high)
+    label.set_text(status, str.tostring(high))

Root causes

  • The script creates a new drawing on every bar without deleting or reusing older IDs.
  • The declaration’s display count is lower than the number of recent objects the chart should retain.
  • Assigning `na` coordinates hides an object but does not remove its ID from the total.

How the fix was verified

Method
Pineify MCP pine-script-syntax-checker; static diagnostics only
Broken result
Returned no grammar diagnostics; drawing retention is evaluated during chart execution.
Fixed result
Returned no grammar diagnostics.
Limit
Not runtime-tested. The correct retention policy depends on drawing type and how many historical objects the chart must show.

Bring the actual script, not just the message

Open the Coding Agent overview to paste editable Pine Script, explain the intended behavior, and request a review. Compile and test the result in TradingView before using it.

Paste your code to fix this error