TradingCharts

Fills

A fill is a tinted region between two plots or two hline levels.

fill(plot1, plot2, color, title?)

upper = ta.sma(close, 20) + ta.stdev(close, 20) * 2
lower = ta.sma(close, 20) - ta.stdev(close, 20) * 2
pU = plot(upper, "Upper",  color=color.aqua)
pL = plot(lower, "Lower",  color=color.aqua)
fill(pU, pL, color=color.new(color.aqua, 85), title="Band")
  • plot1 / plot2 are the handles returned by plot() or hline().
  • color can be a series — the fill tint recalculates per bar.
  • Title appears in the Style tab so the user can switch the fill on/off.

Named arguments

fill(plot1 = pU, plot2 = pL, color = color.new(color.aqua, 85))
fill(hline1 = h1, hline2 = h2, color = color.new(color.orange, 90))

Dynamic fills

Both the plot values and the colour can vary per bar:

pUp = plot(close, color=close > open ? color.lime : na)
pDn = plot(open,  color=close > open ? color.red  : na)
fill(pUp, pDn, color=close > open ? color.new(color.lime, 85) : color.new(color.red, 85))

Gradient fills

Supply top_color/bottom_color/top_value/bottom_value for a vertical gradient between the two plots:

fill(pU, pL,
     top_value    = upper, top_color    = color.new(color.lime, 70),
     bottom_value = lower, bottom_color = color.new(color.red,  70))
  • top_value / bottom_value are the series anchors (usually the plot values themselves).
  • The gradient is drawn linearly between those anchors each bar.

fillgaps for na bars

Pass fillgaps = true to bridge over na bars instead of stopping the fill:

fill(pU, pL, color=color.new(color.aqua, 85), fillgaps=true)

linefill.new() for arbitrary line pairs

When the two lines are line.new() drawings rather than plots, use linefill:

l1 = line.new(bar_index - 10, high, bar_index, high, color=color.lime)
l2 = line.new(bar_index - 10, low,  bar_index, low,  color=color.red)
linefill.new(l1, l2, color=color.new(color.yellow, 90))

The returned reference can be deleted or recoloured later with linefill.set_color() / linefill.delete().

See also