Skip to content
ChartDeck ChartScript docs Account Open the terminal

CS3201

error alert.on can only be used at the top level of the script.

#What it means

alert.on declares a named alert condition that appears in the "Create alert" dialog. The list is fixed when the script is compiled, so alert.on must be at the top level, not inside a condition, loop or function.

#Typical cause

  • alert.on placed inside an if to fire only sometimes.

#How to fix it

Move it to the top level and put the condition in its first argument. To send a message from inside a condition, use alert.send. See Alerts.

#Example

ChartScriptError: CS3201
//@chartscript 1
indicator("Up bar alert")
if (close > open) {
    alert.on(true, "Up bar")
}
plot(close)

Fixed

ChartScriptOpen in editor
//@chartscript 1
indicator("Up bar alert")
alert.on(close > open, "Up bar")
plot(close)
  • CS3007 — name can only be used at the top level of the script, not inside a condition, loop or function.
  • CS3003 — A script can have at most max alert conditions.

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