linefill namespace
linefill
Section titled “linefill”Overview
Section titled “Overview”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.
Constructor
Section titled “Constructor”linefill.new(line1, line2, color, fillgaps) → linefillParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
line1 | series line | Handle to the first line. |
line2 | series line | Handle to the second line. |
color | series color | Fill color (including transparency). |
fillgaps | series bool (optional) | When true, spans empty bars between the two lines. Defaults to true. |
Returns
Section titled “Returns”linefill — handle that represents the fill between the supplied lines.
Remarks
Section titled “Remarks”- 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).
Example
Section titled “Example”//@version=5indicator("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 = navar line slowLine = navar 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))