Skip to content
ChartDeck ChartScript docs Account Open the terminal

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_count in indicator() to calculate fewer bars. See Performance and Profiling.

#Example

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

ChartScriptOpen in editor
//@chartscript 1
indicator("Light")
let total = 0.0
for (let i = 0; i <= 99; i++) {
    total += math.sqrt(i) * math.sin(i)
}
plot(total)
  • CS5402 — Stopped: one live update took too long (ms ms; the limit is max ms).
  • CS5303 — Loops ran more than max times in total on one bar.

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