Skip to content
ChartDeck ChartScript docs Account Open the terminal

CS1053

error break ends a switch case only as its last statement.

#What it means

Switch cases never fall through: each case ends where the next case or default starts. A break as the last statement of a case is accepted (and does nothing). A break anywhere else in a case, for example inside an if, cannot leave the case early.

#Typical cause

  • A break inside an if in a case, meant to skip the rest of the case.

#How to fix it

Put the rest of the case in an if / else instead, or drop the break. See Conditionals.

#Example

ChartScriptError: CS1053
//@chartscript 1
indicator("Mode")
const mode = 2
let s = 0
switch (mode) {
    case 1:
        s = 1
    case 2:
        if (close > open) {
            break
        }
        s = 2
}
plot(s)

Fixed

ChartScriptOpen in editor
//@chartscript 1
indicator("Mode")
const mode = 2
let s = 0
switch (mode) {
    case 1:
        s = 1
    case 2:
        if (close <= open) {
            s = 2
        }
}
plot(s)
  • CS2703 — word can only be used inside a loop.

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