FAQ – How to change bar colors in TradingView / Pine Script?

By default TradingView colors candlestick in 2 colors: green when close > open and red if close < open.

Quite often you might want to change the standard coloring of the bars for your indicators. Fortunately, it’s really easy to change these colors in TradingView.

There are 2 ways to do that, In this article, I will show you both ways:

  • Change default colors for rising and falling bars
  • Change bar colors based on custom conditions in PineScript.

Changing default colors

To change default candle colors you can go to TradingView chart settings. To do that click right-click on the chart and select Settings in the pop-up menu:

In this menu you on the “Symbol” tab you can find several parameters for default bars colors:

Here you can change colors for candle body, borders, and wicks. Also, you can choose to color bars based on the previous close and not the current one.

For every color, you can select the color itself and the opacity of your bars as well. You can choose one of the preselected colors for you and also you can add any color by pressing “+” in the bottom.

For example, you can make your chart looks like this:

Changing colors from PineScript

Also, you can change bar colors from PineScript indicators directly. This will help you to make your indicator more powerful and better display your ideas visually.

In Pine Script you have a function “barcolor” that will help you to color current chart bars from the script. In the simplest case you can just use this function with the single param:

barcolor(color.red)

This will color all your colors red:

This is not super useful, fortunately, you can make this color dynamic depend on some circumstances. You can use multiple colors here and not only 2 as you have in default behavior. Let’s for example create a dynamic color of the bar depend on where the price is located compared to 2 EMAs. I’ll use “?:” conditional operator to assign one of 3 colors to the bar. Here is the code I’m using:

//@version=4
study("My Script", overlay = true)
plot(close)

ma1 = sma(close, 10)
ma2 = sma(close, 50)

bcolor = close > ma1 and close > ma2 ? color.green : 
         close < ma1 and close < ma2 ? color.red : 
         color.blue

plot(ma1, color = color.red)
plot(ma2, color = color.blue)

barcolor(bcolor)

This will color bars in 3 colors:

As you can see it’s a pretty simple task in Pine Script. Just using 1 function you can change the colors of your bars.


Follow me on TradingView and YouTube.