Skip to content
ChartDeck ChartScript docs Account Open the terminal

CS5103

error A collection can hold at most max elements.

#What it means

A collection grew past its limit (given in the message): 100,000 elements for an array or a matrix, 50,000 entries for a map, 10,000 points for a polyline.

#Typical cause

  • A state array that gets new elements on every bar and is never trimmed.

#How to fix it

Keep only what you need: remove old elements as you add new ones (for example if xs.size() > 500 then xs.shift()). See Collections and Performance.

#Example

ChartScriptOpen in editor
//@chartscript 1
indicator("All closes")
state all: float[] = array.new<float>()
for (let i = 0; i <= 999; i++) {
    all.push(close)
}
plot(all.size())

Fixed

ChartScriptOpen in editor
//@chartscript 1
indicator("Recent closes")
state recent: float[] = array.new<float>()
recent.push(close)
if (recent.size() > 500) {
    recent.shift()
}
plot(recent.size())
  • CS5403 — Stopped: the script used more memory than allowed.
  • CS5104 — A string can be at most max characters.

The ChartScript documentation is in English for now; translations will follow.