CS2404
error name cannot be changed (it is what).
#What it means
This name cannot be given a new value. The message says why: it is built in (like close or bar_index), declared with const, a function, a loop variable or a parameter.
#Typical cause
- Assigning to a built-in series, such as
close = .... - Changing a variable declared with
const. - Changing a function parameter inside the function, or the variable of a
forloop inside its body.
#How to fix it
For a const variable that has to change, declare it with let (the editor offers this quick fix). Otherwise declare your own variable with let and change that instead.
#Example
//@chartscript 1
indicator("Smoothed close", { overlay: true })
close = (close + close[1]) / 2
plot(close)Fixed
//@chartscript 1
indicator("Smoothed close", { overlay: true })
const smooth = (close + close[1]) / 2
plot(smooth)