fbpx
Sponsored
Sponsored

Home > Blog > Pine Script Tutorial > How to Plot shapes and change colour in Pine Script

How to Plot shapes and change colour in Pine Script

Published by Ali Muhammad
Updated on

This article will cover the topic of coloring the background of charts in tradingview, coloring candlesticks, and plotting different types of shapes on the chart. Colouring is important to highlight important points or levels on the chart.

  • Coloring background
  • Coloring candlesticks
  • Plotting shapes

Change Background color

There are two functions in the pine script that are used to color the background on the chart.

  • fill(line1, line2)
  • bgcolor(color=color.red)

fill is a built-in function in pine script that is used to color the background between two lines. You need to specify the limits in the fill function. It will fill the space between two lines with color. All other options are available like offset, length, and transparency.

You can also make overlay true or false according to the requirement.

study("My Script", overlay=true)
bgcolor(color=color.red)
high1 = plot(high)
low2 = plot(low)
fill(high1,low2, color=color.black, transp=50)

bg color means background color. This function in the pine script is used to color the complete background of the chart. Use appropriate background color to highlight the color of candlesticks.

The most important use of this function is to highlight different trading sessions (London session, Tokyo session, Asian session) in the forex market.

study("My Script", overlay=true)
bgcolor(color=color.red)
plot(high)
plot(low)
background color pine script
bgcolor

Coloring Candlesticks in Pine script

Bar color is a built-in function that is used to color candlesticks in the pine script programming language. A lot of customizations regarding candlesticks color can be done using this function.

This function is specially set for candlesticks that are why it does not matter either overlay is true or false. It will change the color of candlesticks according to input.

study("My Script", overlay=true)
barcolor(color=color.blue)
plot(high)
plot(low)
coloring candlesticks
Coloring candlesticks

Plotting shapes in Pine Script

Plotting shapes on the chart is one of the useful methods to indicate a signal either bullish or bearish depending on the arrow’s direction. A beginner can easily pick a trading signal by looking at the arrow direction.

There are different types of shapes available in the pine script language.

  • Arrow
  • Triangle
  • Crosses
  • Circles
  • Diamond
  • Square
  • Labels

plot arrow is the built-in function that is used to plot arrows on the chart to forecast price direction in the pine script. If the input value is negative, then it will plot a down arrow. On the other side, if the value is positive then it will plot an up arrow. Arrow length and color can also be customized easily.

The built-In function that is used to plot shapes in pine editor is plot shape. You can also change the location of shapes on the bar by typing shape. And a dropdown will appear. Choose the appropriate location of shape from the drop-down menu.

Look at the code below. If open is greater than close, then it will plot shape above the candlestick.

study("My Script", overlay=true)
high1 = plot(high)
low2 = plot(low)
fill(high1,low2, color=color.black, transp=50)
shape1 = open>close
plotshape(shape1, style=shape.diamond, color=color.red, transp=50)
plot shape in pine script
diamond shape

I hope you will like this Article. For any Questions Comment below, also share by below links.

Note: All the viewpoints here are according to the rules of technical analysis. we are not responsible for any type of loss in forex trading.

Do you want to get success in Trading?

Here's the Roadmap:

1. Learn supply and demand from the cheat sheet here
2. Get access the Supply & Demand Indicator here
3. Understand the fair value gap here
4. Use the set and forget strategy here
5. Follow the risk management plan here

Leave a Comment