CS2701
error A condition must be a bool, but this is got.
#What it means
The condition of an if, a while, a ?: or a switch case must be a bool (true or false). This one has another type, shown in the message.
#Typical cause
- A string or a colour used as a condition.
- A comparison left unfinished, as in
if modeinstead ofif mode == "up".
#How to fix it
Compare the value with something to get a bool. See Conditionals.
#Example
//@chartscript 1
indicator("Mode")
const mode = input.string("up", "Mode", { options: ["up", "down"] })
let level = 0
if (mode) {
level = 1
}
plot(level)Fixed
//@chartscript 1
indicator("Mode")
const mode = input.string("up", "Mode", { options: ["up", "down"] })
let level = 0
if (mode == "up") {
level = 1
}
plot(level)