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

Simple 3-EMA Crossover Trading Strategy - Free Profitable TradingView Strategy Script (+ Source Code)

SIMPLE 3-EMA CROSSOVER TRADING STRATEGY FOR BEGINNERS Risk Disclaimer ❗ The information provided on this post does not constitute investment advice, financial advice, trading advice, or any other sort of advice, and you should not treat any of the posts's content as such. Free Trading View Scripts does not recommend any cryptocurrency should be bought, sold or held by you. Do conduct your own due diligence and consult your financial advisor before making any investment decisions. Introduction In this post, I’m gonna show you a simple yet profitable trading strategy that anyone can use to trade crypto. We’ll only be using one type of indicator and that is the Exponential Moving Average. Later in this post i’ll help you code this strategy using tradingview pinescript so that we can easily backtest historical data and see if this strategy has a chance or not. Before we start, you might want to use my referral link on Binance

How to Add an ATR Trailing Stoploss to Your Strategy - TradingView Script (+ Source Code)

How to Add an ATR Trailing Stoploss to Your Strategy in TradingView Risk Disclaimer ❗ The information provided on this post does not constitute investment advice, financial advice, trading advice, or any other sort of advice, and you should not treat any of the posts's content as such. Free Trading View Scripts does not recommend any cryptocurrency should be bought, sold or held by you. Do conduct your own due diligence and consult your financial advisor before making any investment decisions. Introduction As promised, in this post we are going to add a trailing stoploss strategy to avoid giving back the profits to the market. Out of all the strategies available for trailing stop, I am choosing the ATR . The main reason I chose this is that the ATR changes based on the volatility of the candles. It takes into account the huge movements of the candle to avoid being whipsawed more often . You’ll see what I’m t

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