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
statearray 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
//@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
//@chartscript 1
indicator("Recent closes")
state recent: float[] = array.new<float>()
recent.push(close)
if (recent.size() > 500) {
recent.shift()
}
plot(recent.size())