CS2402
warning This declares a new name that hides the one from line line; did you mean to change it with op ?
#What it means
This is a warning. Inside a block, let name = ... or const name = ... declares a new variable that hides the one with the same name outside the block. The outer variable keeps its old value, which is rarely what you want.
#Typical cause
- Writing
letorconstinside anifor a loop when you meant to change the outer variable.
#How to fix it
Drop the let / const and write name = ... to change the existing variable (declared with let or state). If you really want a separate one, give it a different name. See Variables.
#Example
//@chartscript 1
indicator("Trend")
const trend = 0
if (close > open) {
const trend = 1
}
plot(trend)Fixed
//@chartscript 1
indicator("Trend")
let trend = 0
if (close > open) {
trend = 1
}
plot(trend)