Barcoloring a series with barcolorΒΆ

The barcolor annotation function lets you specify the color of bars. The coloring can be conditional. The following script renders inside and outside bars in different colors:

study("barcolor example", overlay=true)
isUp() => close > open
isDown() => close <= open
isOutsideUp() => high > high[1] and low < low[1] and isUp()
isOutsideDown() => high > high[1] and low < low[1] and isDown()
isInside() => high < high[1] and low > low[1]
barcolor(isInside() ? color.yellow : isOutsideUp() ? color.aqua : isOutsideDown() ? color.purple : na)

As you can see, the na value leaves bars as is.

barcolor works whether the script is running in overlay=true mode or not.

Options v: v4