Resource limit

Fix too many Pine Script drawings

Reuse or delete drawing IDs instead of creating an unbounded stream of new objects. Pine displays only a recent subset of lines, boxes, polylines, and labels by default, and each drawing type also has an ID limit. The fixed script creates one label with `var` and updates it on the last bar. Increase a declaration limit only when the chart genuinely needs more retained drawings.

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 UAT grammar checker via check-pine-script-grammar.mjs
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