if and switch choose which statements run on a bar. Both are statements with no value, so x = if ... is a syntax error; to choose
a value use c ? a : b (see Operators and expressions).
if, else if, else
bool or a number (zero is false, and so is na). A string is refused: if conditional expression must be of a bool
type!. Braces and line breaks follow Statements and lines. A variable declared inside a
block is not visible after it, so declare it before the if and assign it with :=.
switch
switch value { is followed by case x: lines and an optional default:.
- The first matching case runs and the
switchends: there is no fall-through and nobreakis needed. - A
casetakes exactly one value (case 0, 1:is a syntax error). Strings and enum members work as values; the value must have the type of the subject (afloatsubject takes anintcase). - At most one
default: Only onedefaultcase is allowed in a switch statement.
What may go inside a branch
The refused calls draw one series for the whole script, so they belong at the top level:
plot() must be called in the global scope. The editor’s check reports it, and the name in the message is the call you wrote.
Put the condition into an argument and give na for the bars you want empty: plot(close > open ? close : na, title="Up close").