> ## Documentation Index
> Fetch the complete documentation index at: https://gocharting.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# How to shade the area between two plots

> Keeping each plot in a variable and passing both to fill, in a plain form with a color per bar and in a gradient form between two prices.

`plot` returns a plot value. Assign each plot to a variable at the top level, then hand both variables to `fill`. Name the arguments:
the form for two horizontal lines takes the color and the title in the opposite order, and names remove the difference.

## Plain fill

`fill(p1, p2, title, color)` shades the band with one color. The color is a series value, so a condition inside it changes the
shade bar by bar. `color.new(color, alpha)` takes an opacity from 0 to 1, so use a low value for a light shade.

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Close against its average", overlay=true)
average = talib.sma(close, 20)
c = plot(close, title="Close", color=color.gray)
a = plot(average, title="Average", color=color.blue)
fill(p1=c, p2=a, title="Gap", color=close > average ? color.new(color.green, 0.2) : color.new(color.red, 0.2))
```

## Gradient fill

The gradient form adds four values: `fill(plot1, plot2, top_value, bottom_value, top_color, bottom_color, title)`. Each bar the
shade runs from `top_color` at `top_value` to `bottom_color` at `bottom_value`, changing gradually between. All four are required;
the values are numbers and may be series, so pass the two prices that bound the band to make the gradient span it on every bar.

```lipi wrap theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Gradient between plots", overlay=true)
upper = talib.highest(high, 20)
lower = talib.lowest(low, 20)
u = plot(upper, title="Upper", color=color.green)
l = plot(lower, title="Lower", color=color.red)
fill(plot1=u, plot2=l, top_value=upper, bottom_value=lower, top_color=color.new(color.green, 0.3), bottom_color=color.new(color.red, 0.3), title="Channel")
```

## Between two levels

For two `hline` values, use `fill(h1, h2, color, title)` or, with a gradient, `fill(h1, h2, top_value, bottom_value, top_color,
bottom_color)`. There is no form that takes a plot and a level.

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Levels", overlay=false)
plot(talib.rsi(close, 14), title="RSI")
top = hline(70, title="Top")
bot = hline(30, title="Bottom")
fill(h1=top, h2=bot, color=color.new(color.blue, 0.2), title="Band")
```

## The mistake to avoid

> [!WARNING]
>
> Mixing a plot and a level. The compiler says: Cannot call `fill` with argument `h1`=`p`. An argument of `series plot` type was used but a `series hline` is expected.
>
> ```lipi-invalid theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
> //@lipi=2
> indicator("Mixed fill", overlay=true)
> p = plot(close, title="Close")
> h = hline(100, title="Level")
> fill(p, h, color=color.new(color.blue, 0.2))
> ```

When you fill between two plots, the fill keeps an offset only if both plots carry the same one. `fill` and the plots it joins must
be called at the top level, and the fill follows its plots into their pane (it has no `force_overlay`). To shade between two lines drawn with `line.new`, use `linefill.new` (see [Lines, labels, boxes and polylines](https://gocharting.com/docs/scripting/chart-output/drawings.md)). See [Fills and levels](https://gocharting.com/docs/scripting/chart-output/fills-and-levels.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.