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
plotorhlineinside anifto 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
//@chartscript 1
indicator("Up closes", { overlay: true })
if (close > open) {
plot(close)
}Fixed
//@chartscript 1
indicator("Up closes", { overlay: true })
plot(close > open ? close : na)