Skip to content

linefill namespace

The linefill namespace pairs two line objects and fills the area between them. This is useful for highlighting price channels, volatility envelopes, or projection cones drawn with line.new.

Set the script’s max_linefill_count input high enough to cover every linefill.new call you make. Otherwise, additional fills are ignored.

linefill.new(line1, line2, color, fillgaps) → linefill
NameTypeDescription
line1series lineHandle to the first line.
line2series lineHandle to the second line.
colorseries colorFill color (including transparency).
fillgapsseries bool (optional)When true, spans empty bars between the two lines. Defaults to true.

linefill — handle that represents the fill between the supplied lines.

  • Changing the style, width, or coordinates of either source line automatically updates the fill on the chart.
  • Use linefill.set_color(id, color) when you need to adjust color dynamically without recreating the fill.
  • To remove a fill without deleting the underlying lines, call linefill.delete(id).
//@version=5
indicator("Moving average ribbon fill", overlay=true, max_lines_count=2, max_linefill_count=1)
fastLen = input.int(21, "Fast length")
slowLen = input.int(55, "Slow length")
fast = ta.ema(close, fastLen)
slow = ta.ema(close, slowLen)
var line fastLine = na
var line slowLine = na
var linefill ribbon = na
if not na(fast) and not na(slow)
if na(fastLine)
fastLine := line.new(bar_index - 1, fast[1], bar_index, fast,
extend = extend.right, color = color.new(color.teal, 0))
slowLine := line.new(bar_index - 1, slow[1], bar_index, slow,
extend = extend.right, color = color.new(color.orange, 0))
ribbon := linefill.new(fastLine, slowLine, color.new(color.teal, 85))
else
line.set_xy1(fastLine, bar_index - 1, fast[1])
line.set_xy2(fastLine, bar_index, fast)
line.set_xy1(slowLine, bar_index - 1, slow[1])
line.set_xy2(slowLine, bar_index, slow)
trendIsUp = fast > slow
linefill.set_color(ribbon, trendIsUp ? color.new(color.green, 80) : color.new(color.red, 80))