Skip to content

barcolor() - Pine Script Function

barcolor() overrides the color of the current chart’s price bars. You can pass a literal color (e.g., color.green) or any series color expression, which makes it ideal for highlighting bullish/bearish regimes. Passing na leaves the bar unchanged.

barcolor(color, offset, editable, show_last, title, display) → void
NameTypeDescription
colorseries colorColor to apply to the bar. Use na to leave the bar unchanged. Required.
offsetseries intShift the application forward (> 0) or backward (< 0) bars. Defaults to 0.
editableconst boolWhether the color can be adjusted from the style settings. Defaults to true.
show_lastseries intApply coloring only to the most recent n bars. Defaults to na (all bars).
titleconst stringLabel shown in the style settings.
displayconst stringWhere the coloring applies (see display.* constants).
  • barcolor() affects only the script that calls it; other indicators on the chart can still override colors.
  • Use color.new(color, transp) to adjust transparency instead of RGB literals.
  • Combine with bgcolor() or plot for additional context, but remember each call counts toward the plot limit.
//@version=5
indicator("barcolor example", overlay=true)
isUp = close >= open
colorUp = color.new(color.green, 0)
colorDown = color.new(color.red, 0)
barcolor(isUp ? colorUp : colorDown)
plotshape(isUp, title="Up", location=location.belowbar, style=shape.triangleup, color=colorUp)
plotshape(not isUp, title="Down", location=location.abovebar, style=shape.triangledown, color=colorDown)