> ## 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.

# Bar coloring and background

> Recoloring the chart's own bars with barcolor and shading the pane background with bgcolor.

`barcolor` recolors the price bars; `bgcolor` shades the background behind a bar. Neither draws a value. Both stand at the top level
and take their condition in the color: a color of `na` means no change.

## barcolor and bgcolor

* `barcolor(color, title, offset, display)`
* `bgcolor(color, title, offset, force_overlay, display)`

`color` may be a series. `title` is a `const string`, `offset` an `input int`. `barcolor` has no `force_overlay`.

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Trend shading", overlay=true)
avg = talib.sma(close, 20)
up = close > avg
barcolor(up ? color.green : color.red, title="Bars")
bgcolor(up ? color.new(color.green, 0.92) : na, title="Uptrend")
```

A gradient shades the background by a value (see [Color](https://gocharting.com/docs/scripting/chart-output/color.md)):

```lipi-fragment theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
rsi = talib.rsi(close, 14)
bgcolor(color.from_gradient(rsi, 30, 70, color.new(color.red, 0.8), color.new(color.green, 0.8)))
```

## display accepts only all and none

`display` takes only `display.none` and `display.all` on both. The editor accepts other constants; adding the script to the chart
refuses them:

```lipi-invalid theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Pane only")
bgcolor(color.red, display=display.pane)
```

The compiler says (when added to the chart): `bgcolor()` display argument only supports display.none and display.all. For `barcolor` the message names `barcolor()`.

To own the whole bar rather than recolor it, use `plotcandle` (see [Plotting](https://gocharting.com/docs/scripting/chart-output/plotting.md)).


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