Colors the background behind a bar, evaluated per bar, with transparency to keep the price visible.
bgcolor tints the full height of the pane behind each bar where color is not na. A condition expression such as cond ? color.new(color.red, 80) : na colors only the bars that match.
Use a transparency of 70 or more so candles and lines stay readable. The offset argument shifts the tint to other bars.
Syntax
bgcolor(color: series color, offset: simple int (optional), editable: input bool (optional), show_last: input int (optional), title: const string (optional), display: input plot_simple_display (optional), force_overlay: const bool (optional)) -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| color | series color | required | Background color, evaluated per bar. na leaves the bar uncolored. |
| offset | simple int | 0 | Shifts the tint by this many bars; negative moves it into the past. |
| editable | input bool | true | Accepted for compatibility and ignored. |
| show_last | input int | na | Accepted for compatibility and ignored. |
| title | const string | "" | Name shown in the Settings dialog. |
| display | input plot_simple_display | display. | Where the tint is shown. display.none hides it. |
| force_overlay | const bool | false | When true, draws on the main chart pane even if the script runs in its own pane. |
Returns
Nothing.
Remarks
- In a script with overlay = false the tint fills the script's own pane. Pass force_overlay = true to tint the main chart instead.
Example
//@version=6
indicator("Trend background", overlay = true)
trendUp = close > ta.sma(close, 50)
bgcolor(trendUp ? color.new(color.green, 92) : color.new(color.red, 92))See also
Runs on Sidechair