Reputation: 987
For example, IF something is bigger than something else then I want to redefine a color variable. If trying, I get the following error:
'IF' is not a valid type keyword in variable declaration
Upvotes: 0
Views: 807
Reputation: 8779
Please refer to the usrman page on Colors where you will find this example, among many others:
//@version=5
indicator("Conditional colors", "", true)
int lengthInput = input.int(20, "Length", minval = 2)
color maBullColorInput = input.color(color.green, "Bull")
color maBearColorInput = input.color(color.maroon, "Bear")
float ma = ta.sma(close, lengthInput)
// Define our states.
bool maRising = ta.rising(ma, 1)
// Build our color.
color c_ma = maRising ? maBullColorInput : maBearColorInput
plot(ma, "MA", c_ma, 2)
Upvotes: 1