SuperCharting
Sign in Get started Account Open charts

Learn / Guides

Pine Script linefill.new: fill the space between two lines

How linefill.new works in Pine Script v5 and v6, a working channel example, how it differs from fill(), and how to update or delete a linefill.

linefill.new(line1, line2, color) colours the space between two lines made with line.new(). It is the drawing version of fill(): fill() joins two plots across every bar, while a linefill joins two drawn lines, wherever they are on the chart. SuperCharting supports linefill.new and its setters in Pine Script v5 and v6.

A working example: a channel of the last 30 bars

//@version=6
indicator("30-bar channel", overlay = true)

len = input.int(30, "Bars")
hi  = ta.highest(high, len)
lo  = ta.lowest(low, len)

var line top = na
var line bot = na
var linefill zone = na

if barstate.islast
    line.delete(top)
    line.delete(bot)
    top  := line.new(bar_index - len, hi, bar_index, hi, color = color.teal)
    bot  := line.new(bar_index - len, lo, bar_index, lo, color = color.teal)
    zone := linefill.new(top, bot, color.new(color.teal, 85))

The two lines mark the highest high and the lowest low of the last 30 bars, and the linefill shades the range between them.

How it behaves

linefill or fill?

UseWhen
fill(plot1, plot2, color)The two edges are series values on every bar, such as Bollinger Bands.
linefill.new(line1, line2, color)The edges are drawn lines: a channel, a range box between two levels, a trend channel from two pivots.

How to try it

  1. Open a chart, for example NSE:NIFTY on the 15m interval.
  2. Open the Pine Editor, paste the example and click Add to chart.
  3. The shaded channel appears over the last 30 bars and moves with every new bar.

The free Pine Script checker checks a script without an account.

Frequently asked questions

Why does linefill.new draw nothing?

Both arguments must be lines that exist. If either is na or was deleted, there is nothing to fill. Create the lines first, then the linefill.

Can a linefill have a gradient?

No. A linefill has one colour. For a gradient, use fill() between two plots with top_color and bottom_color.

Try it on a live chart

SuperCharting is an AI-enabled charting and coding platform in your browser: charts, Pine-compatible scripts with AI Auto-fix, the Strategy Tester, alerts and the screener.

Create a free account More guides