Skip to content
ChartDeck ChartScript docs Account Open the terminal

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.isrealtime or barstate.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

ChartScriptOpen in editor
//@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

ChartScriptOpen in editor
//@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)
  • CS5401 — Stopped: the script took too long (ms ms; the limit is max ms).
  • CS5404 — Stopped: the script stopped answering and was shut down.

The ChartScript documentation is in English for now; translations will follow.