Alert when change of color indicator

27 Views Asked by At

Hello everyone I'm looking to create an alert every time this tradingview indicator changes his colors !

This is the script, could you help me please ?

//@version=3
study("OBOS")

hline(100)
hline(-100)
length=input(9,title="Lenggth")
ys1=(high+low+close*2)/4
rk3=ema(ys1,length)
rk4=stdev(ys1,length)
rk5=(ys1-rk3)*100/rk4
rk6=ema(rk5,length)
up=ema(rk6,length)
down=ema(up,length)
Oo=up<down?up:down
Hh=Oo
Ll=up<down?down:up
Cc=Ll
barcolor2=Oo[1]<Oo and Cc<Cc[1]?blue:up>down?green:red
plotcandle(Oo,Hh,Ll,Cc,color=barcolor2)


Create an alert every time this indicator changes his colors. So when he changes from green / blue / red

1

There are 1 best solutions below

1
vitruvius On

barcolor2 is the variable that holds the color information. You can use this to see if it is a new color and set your alerts.

new_green = (barcolor2[1] != green) and (barcolor2 == green)
new_red = (barcolor2[1] != red) and (barcolor2 == red)
new_blue = (barcolor2[1] != blue) and (barcolor2 == blue)

alertcondition(new_green, "New green")
alertcondition(new_red, "New red")
alertcondition(new_blue, "New blue")