Sidechair

bgcolor()

Browse the reference

Colors the background behind a bar, evaluated per bar, with transparency to keep the price visible.

Try it in the editor

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

Pine Script
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)) -> void

Arguments

NameTypeDefaultDescription
colorseries colorrequiredBackground color, evaluated per bar. na leaves the bar uncolored.
offsetsimple int0Shifts the tint by this many bars; negative moves it into the past.
editableinput booltrueAccepted for compatibility and ignored.
show_lastinput intnaAccepted for compatibility and ignored.
titleconst string""Name shown in the Settings dialog.
displayinput plot_simple_displaydisplay.allWhere the tint is shown. display.none hides it.
force_overlayconst boolfalseWhen 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

Pine ScriptHighlight a trend regimeOpen in editor
//@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