Runtime errorRE10139

Fix RE10139: Memory limits exceeded

Stop returning a growing collection from `request.security()` on every bar when a scalar result is enough. Pine copies requested collection data across datasets, so persistent arrays can consume memory quickly over long histories. Return only the value required by the chart, limit requested history, and update drawings or buffers only when needed. The fixed example requests `close` directly instead of copying an expanding array.

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("Memory limit demo")
dataFunction() =>
    var array<float> data = array.new<float>()
    data.push(close)
    data
array<float> requested = request.security(syminfo.tickerid, "1D", dataFunction())
plot(requested.last())
Fixed code.pine
//@version=6
indicator("Memory limit demo")
float requested = request.security(syminfo.tickerid, "1D", close)
plot(requested)
Diff.pine
--- broken.pine
+++ fixed.pine
@@
-dataFunction() =>
-    var array<float> data = array.new<float>()
-    data.push(close)
-    data
-array<float> requested = request.security(syminfo.tickerid, "1D", dataFunction())
-plot(requested.last())
+float requested = request.security(syminfo.tickerid, "1D", close)
+plot(requested)

Root causes

  • `request.*()` returns collection or object IDs that are copied across bars and contexts.
  • Historical buffers or `max_bars_back` values retain more data than the calculation needs.
  • Drawing objects are repeatedly updated or retained when fewer objects would represent the same result.

How the fix was verified

Method
Pineify UAT grammar checker via check-pine-script-grammar.mjs
Broken result
Returned no grammar diagnostics; the memory failure requires dataset execution.
Fixed result
Returned no grammar diagnostics.
Limit
Not runtime-tested. Memory consumption depends on dataset length, requested contexts, collections, buffers, and drawings.

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