Skip to content
ChartDeck ChartScript docs Account Open the terminal

CS3007

error name can only be used at the top level of the script, not inside a condition, loop or function.

#What it means

Some statements describe the script as a whole and must sit at the top level: plots and other outputs, hline, inputs, types, enums, import and the declaration. They cannot be inside an if, a loop or a function.

#Typical cause

  • A plot or hline inside an if to show it only sometimes.
  • An input or a type declared inside a function.

#How to fix it

Move the statement to the top level. To show a plot only sometimes, give it a value of na on the other bars: plot(cond ? x : na). See Plots.

#Example

ChartScriptError: CS3007
//@chartscript 1
indicator("Up closes", { overlay: true })
if (close > open) {
    plot(close)
}

Fixed

ChartScriptOpen in editor
//@chartscript 1
indicator("Up closes", { overlay: true })
plot(close > open ? close : na)
  • CS2710 — name can only be used at the top level of the script.
  • CS3201 — alert.on can only be used at the top level of the script.
  • CS2502 — Functions cannot be declared inside other functions.

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