CS5303
error Loops ran more than max times in total on one bar.
#What it means
All loops together ran more than the allowed number of passes on a single bar (the message gives the limit, 1,000,000). This often happens with nested loops, where the passes multiply.
#Typical cause
- Nested loops such as 2,000 x 1,000 passes on every bar.
#How to fix it
Reduce the work per bar: shorten the loops, compute once and reuse the result, or keep running values from bar to bar. See Performance.
#Example
//@chartscript 1
indicator("Nested loops")
let total = 0.0
for (let i = 0; i <= 1999; i++) {
for (let j = 0; j <= 999; j++) {
total += 1
}
}
plot(total)Fixed
//@chartscript 1
indicator("Nested loops")
const total = 2000.0 * 1000.0
plot(total)