Home » Color Functions » Introduction to Fills Function in Pine Script

Introduction to Fills Function in Pine Script

Photo of author
Published on

Understanding the fill() Function

Pine Script offers a range of tools to enhance the visual aspects of your trading strategies. One such feature is the ability to fill the space between various chart elements. The fill() function plays a pivotal role in this, allowing users to color the background between two specific elements.

Use with plot()

The plot() function in Pine Script is commonly used for drawing lines on a chart, representing data like moving averages or custom indicators. By using fill() in conjunction with plot(), you can create a colored background between two plotted lines. This can be particularly useful for highlighting the areas between important thresholds or indicators.

Use with hline()

Similarly, hline(), which is used for drawing horizontal lines at specific price levels, can be enhanced using fill(). Filling the area between two hline() calls can provide a visual representation of a range, such as a support and resistance zone.

The linefill.new() Function

With the introduction of Pine Script Version 5, a new function named linefill.new() was added. This function specifically targets lines created using line.new().

Application

linefill.new() is instrumental in filling the space between two lines. Unlike fill(), which works with plot() and hline(), linefill.new() is dedicated to lines. This is particularly useful for custom drawn lines, where you need to fill the space between these lines based on certain conditions or thresholds.

Leave a Comment