Skip to main content

How to Change Bar Colors in TradingView / Pine Script?

 How to change bar colors in TradingView / Pine Script?

Free TradingView Scripts - How to Change Bar Colors in TradingView / Pine Script?


There are basically two ways to change the color of the candles in tradingview. Here are they:
  1. Opening the Chart Settings
  2. Using a Script

Opening the Chart Settings

  1. Click the settings in tradingview chart, the one with the cog icon.
  2. Click the Symbol tab on the chart settings.
  3. Easily modify the colors by changing the candle's settings (body, borders, wick).

Free TradingView Scripts - Chart Settings
Chart Settings - Bar Colors

Using a Script

First let's hide the current bar colors by unticking the checkbox on chart settings > symbol.

Free TradingView Scripts - Hide Default Candles
Hiding the Default Bar Colors


After we hide the default candle colors we can now create our own custom candle script.

Plotting Candles w/ Pine Script

We can do that by:


Free TradingView Scripts - Plotting Candles w/o Colors Using Script
Plotting Candles using Script (w/o Color)

In the code above the plotcandle() function accepts open, high, low and close as the first 4 parameters. It successfully plot the candles but the next problem is that the colors are all the same, they are all blue. Now, we only need to fix the colors of the candle.

Black And White Colored Candles

Our next goal is to use color the candles with black and white. Let's print the candle white if the candle is bullish and black if bearish. We can do that by:


Free TradingView Scripts - Black & White Colored Candles
Black & White Color


RSI Overbought and Oversold Candles

Now that you know how to color candles based on simple conditions, we can then go to a little more complex. Let's say we are using RSI as oversold and overbought strategy. Let's color our candles green if it's oversold (since it's a bargain) and color the candles red if it's overbought (means too expensive).

First thing we need to do is to get the inputs of the rsi. We will need the rsi length, overbought level and oversold level. Then we need to have a condition that says if RSI is overbought and oversold.


Then now we can start drawing the candles. If you have more than one condition and two colors for drawing the candles, it's better to separate and draw each condition one by one.

First we will draw the overbought candles. We will pass na which means empty when the rsi is not overbought. In short we only draw the candles if the RSI is overbought. We will color overbought candles with red color.


Free TradingView Scripts - Overbought Candles
Overbought Candles


Next is the oversold candles


Free TradingView Scripts - Oversold Candles
Oversold Candles


Last is if RSI is neither overbought nor oversold then we will use the black and white color


Free TradingView Scripts - Complete Overbought and Oversold Custom Candles Script
Complete Overbought and Oversold Custom Candle Script


Conclusion

Now we can use the methods above to color the candles based on our taste, strategy and preferences. And if ever we have a complex trading strategy in mind, we can always use custom candles to create easy-to-understand visuals that will help us have a one glance look of our strategy.

With these, we have another tool in our arsenal that we can use in conjunction with our trading strategy.


Free TradingView Scripts - Big Picture w/ Custom Candles Script
Big Picture



Source Code

You can view the full source code here: source code

A Little Favor From You 😅

Since I give everything for free in this blog, please have time to support the blog by following or subscribing to some of my social media accounts:

👉 Youtube Channel

👉 Blog







Comments

Popular posts from this blog

Source Code - Simple 3-EMA Crossover + ATR Trailing Stoploss - TradingView Strategy

Source Code of Simple 3-EMA Crossover + ATR Trailing Stoploss TradingView Strategy Script Related links Link to the blog post Youtube video Source Code A Little Favor From You 😅 Since I give everything for free in this blog, please have time to support the blog by following or subscribing to some of my social media accounts: 👉 Youtube Channel 👉 Blog

How to Draw Lines in TradingView Pinescript?

 How to draw lines in TradingView pinescript? There are 3 ways that I know of on how to draw lines in TradingView  pinescript. And, these are: hline() plot() line.new() hline() The hline() or Levels are used to plot horizontal lines across the chart. It is commonly used in RSI to indicate the oversold and overbought levels . Let's say we have an oscillator that is very similar to RSI and we want to plot the oversold and overbought levels,  we can do that easily by calling the hline function: hline (price, title, color, linestyle, linewidth, editable) → hline And here's the example of trying to use the function: And here's the result when plotted to chart RSI + Levels (30, 50, 70) plot() The plot() function is often used to draw almost all lines in TradingView pinescript.

Source Code - Simple 3-EMA Crossover TradingView Strategy

Source Code of Simple 3-EMA Crossover TradingView Strategy Script Related links Link to the blog post Link to youtube video version Source Code A Little Favor From You 😅 Since I give everything for free in this blog, please have time to support the blog by following or subscribing to some of my social media accounts: 👉 Youtube Channel 👉 Blog