Pine Script Tutorial

How to Plot shapes and change colour in Pine Script

This article will cover the topic of colouring the background of charts in tradingview, colouring 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 colour the background on the chart.

  • fill(line1, line2)
  • bgcolor(

fill is a built-in function in pine script that is used to colour the background between two lines. You need to specify the limits in the fill function. It will fill the space between two lines with colour. 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)
high1 = plot(high)
low2 = plot(low)
fill(high1,low2,, transp=50)

bgcolor means background colour. This function in the pine script is used to colour the complete background of the chart. Use appropriate background colour to highlight the colour 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)
background color pine script

Coloring Candlesticks in Pine script

Barcolor is a built-in function that is used to colour candlesticks in the pine script programming language. A lot of customizations regarding candlesticks colour 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 colour of candlesticks according to input.

study("My Script", overlay=true)
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 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

plotarrow is the built-in function that is used to plot arrows on the chart to forecast price direction in 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 up arrow. Arrow length and colour can also be customized easily.

The built-In function that is used to plot shapes in pine editor is plotshape. 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,, transp=50)
shape1 = open>close
plotshape(shape1, style=shape.diamond,, 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.

Tagged , ,

Leave a Reply

Your email address will not be published. Required fields are marked *