Reputation: 1
I have multiple conditions like;
Buy1 Buy2 Buy3 Buy4 Buy5 . . . Buy10
I want to change bar colors due to TRUE condition numbers Example: only buy1 true If 1 Condition True barcolor(color.red) Example: only buy1, buy3, buy5 true If 3 Condition True barcolor(color.blue) If 9 Condition True barcolor(color.green) . .
how can i code, thanks for your help
Upvotes: 0
Views: 3030
Reputation: 21372
You cannot use both plot()
and alertcondition()
in local scope. What you can do is, write your condition in series/condition
argument of plot/alertcondition
.
Below plot()
call will plot the close
value wheneever buy1 and buy2
is true.
plot(buy1 and buy2 ? close : na)
alertcondition(buy1 and buy2, "Title", "Message")
You can pretty much use the ternary operator for every parameter of a function.
To change the color of a bar, use the ternary operator to set its color
argument.
//@version=5
indicator("My Script", overlay=true)
cond = high > high[1]
barcolor(cond ? color.yellow : na)
Upvotes: 1