Functions
fill()
Shades the band between two plots, or between two horizontal lines. It has two forms and no mixed one, so you cannot fill between a plot and a level, and like the other output calls it must sit at the top level. The forms differ in argument order, and that is the thing that bites: for two levels the third argument is the colour, for two plots it is the title. Name the arguments and the difference stops mattering. When you fill between two plots, the fill keeps an offset only if both plots carry the same one.
Syntax · 1 of 2
fill(series hline h1, series hline h2, series color color, const string title, const bool fillgaps) → void
Arguments
h1 required series hline The first horizontal line. Required in the level form. h2 required series hline The second horizontal line. Required in the level form. color series color The fill colour. Series-form. Third argument in the level form, fourth in the plot form. title const string The fill's name. Const-form. Fourth argument in the level form, third in the plot form. fillgaps const bool Whether gaps are filled. Const-form, so it is fixed for the run of the script. Last argument in both forms. Return Type
void Syntax · 2 of 2
fill(series plot p1, series plot p2, const string title, series color color, const bool fillgaps) → void
Arguments
p1 required series plot The first plot. Required in the plot form. p2 required series plot The second plot. Required in the plot form. title const string The fill's name. Const-form. Fourth argument in the level form, third in the plot form. color series color The fill colour. Series-form. Third argument in the level form, fourth in the plot form. fillgaps const bool Whether gaps are filled. Const-form, so it is fixed for the run of the script. Last argument in both forms. Return Type
void Example
indicator("Fill Example", overlay=true)
// Create two moving averages
ma1 = ta.sma(close, 20)
ma2 = ta.sma(close, 50)
// Plot moving averages
plot1 = plot(ma1, color=color.blue, title="MA 20")
plot2 = plot(ma2, color=color.orange, title="MA 50")
// Fill the area between MA 20 and MA 50
fill(plot1, plot2, color=color.new(color.green, 0.1))