CS5402
error Stopped: one live update took too long (ms ms; the limit is max ms).
#What it means
One live update of the current bar took longer than allowed (the message gives the time and the limit). Live updates must be quick so the chart keeps up with the market, so the script was stopped.
#Typical cause
- Heavy work that runs on the live bar, such as large loops or sorts guarded by
barstate.isrealtimeorbarstate.islast.
#How to fix it
Move the heavy work out of the live bar, do it only when a bar closes (barstate.isconfirmed), or make it smaller. See Performance.
#Example
//@chartscript 1
indicator("Live heavy")
let total: float = 0.0
if (barstate.isrealtime) {
for (let k = 0; k <= 7; k++) {
const xs = array.new_float(0)
for (let i = 0; i <= 99999; i++) {
xs.push(math.sin(i * close))
}
xs.sort()
total += xs.get(0)
}
}
plot(total)Fixed
//@chartscript 1
indicator("Live light")
let total: float = 0.0
if (barstate.isrealtime) {
const xs = array.new_float(0)
for (let i = 0; i <= 999; i++) {
xs.push(math.sin(i * close))
}
xs.sort()
total += xs.get(0)
}
plot(total)