Runtime errorRE10143

Fix RE10143: historical offset beyond buffer limit

Size the specific historical buffer for the largest offset the script can request on any historical or realtime bar. The broken script trains the automatic buffer on 500 bars, then asks for 1,000 on realtime data, after Pine has stopped resizing it. `max_bars_back(close, 1000)` declares that requirement. Do not enlarge every buffer blindly, and never request beyond Pine’s supported history limit.

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("Historical buffer demo")
float value = close[barstate.ishistory ? 500 : 1000]
plot(value)
Fixed code.pine
//@version=6
indicator("Historical buffer demo")
max_bars_back(close, 1000)
float value = close[barstate.ishistory ? 500 : 1000]
plot(value)
Diff.pine
--- broken.pine
+++ fixed.pine
@@
+max_bars_back(close, 1000)

Root causes

  • A realtime branch requests a larger offset than any branch used while historical buffers were sized.
  • A drawing anchored far in the past needs a larger `time` buffer even when its coordinates use `bar_index`.
  • A dynamic offset exceeds the supported history limit rather than only the current automatic buffer.

How the fix was verified

Method
Pineify UAT grammar checker via check-pine-script-grammar.mjs
Broken result
Returned no grammar diagnostics; the documented failure occurs on realtime execution.
Fixed result
Returned no grammar diagnostics.
Limit
Not runtime-tested. Reproduce realtime-only cases with live data or Bar Replay and size only the affected series.

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