CS5401
error Stopped: the script took too long (ms ms; the limit is max ms).
#What it means
Calculating the script over the chart's history took longer than the time allowed (the message gives the time used and the limit). The script was stopped so the chart stays responsive.
#Typical cause
- Heavy loops that run on every bar.
- Large collections sorted or copied on every bar.
#How to fix it
- Do expensive work only where it is needed, for example on the last bar (
barstate.islast). - Replace loops with running values or built-in
ta.*functions. - Use
calc_bars_countinindicator()to calculate fewer bars. See Performance and Profiling.
#Example
//@chartscript 1
indicator("Heavy")
let total = 0.0
for (let i = 0; i <= 99999; i++) {
total += math.sqrt(i) * math.sin(i)
}
plot(total)Fixed
//@chartscript 1
indicator("Light")
let total = 0.0
for (let i = 0; i <= 99; i++) {
total += math.sqrt(i) * math.sin(i)
}
plot(total)