CS5301
error A loop ran more than max times on one bar.
#What it means
One loop ran more than the allowed number of passes on a single bar (the message gives the limit, 100,000). The script was stopped so it cannot hang the chart.
#Typical cause
- A loop bound that is far larger than intended.
- A
whileloop whose condition never becomes false.
#How to fix it
Check the loop's bounds and exit condition. Often a running total kept from bar to bar replaces a big loop. See Loops and Performance.
#Example
//@chartscript 1
indicator("Big loop")
let total = 0.0
for (let i = 0; i <= 200000; i++) {
total += i
}
plot(total)Fixed
//@chartscript 1
indicator("Big loop")
const n = 200000
const total = n * (n + 1) / 2
plot(total)