BACKGROUNDCOLOR
BACKGROUNDCOLOR in ProBuilder tints the chart background per bar using RGB and an alpha value, to highlight conditions on an indicator. Syntax and examples.
Syntax
BACKGROUNDCOLOR(R, G, B, a)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
R | integer | required | Red component of the colour, 0 to 255. |
G | integer | required | Green component of the colour, 0 to 255. |
B | integer | required | Blue component of the colour, 0 to 255. |
a | integer | required | Alpha (transparency), 0 fully transparent to 255 fully opaque. |
How it works
BACKGROUNDCOLOR runs inside a ProBuilder indicator. On each bar where it is called it sets the colour of the chart background behind that bar. Since it applies per bar, it is normally driven by a condition, so ranges of bars are shaded to mark a regime, a threshold breach or a directional bias.
A moderate alpha value keeps the tint behind the price bars readable. Colours are given as RGB components, the same additive model used by COLOURED and FILLCOLOR. Unlike FILLCOLOR, which fills a drawn object, BACKGROUNDCOLOR tints the whole background column at that bar.
Examples
Example 1, Shade by stochastic bias (Indicator)
// Green background while bullish, red while bearish
sto = Stochastic[10,3](close)
signal = Average[5](sto)
rge = AverageTrueRange[10](close)
IF sto[1] > 80 AND sto CROSSES UNDER signal THEN
DRAWARROWDOWN(BarIndex[1], high[1] + rge/2) COLOURED(255, 10, 10)
direction = -1
ELSIF sto[1] < 20 AND sto CROSSES OVER signal THEN
DRAWARROWUP(BarIndex[1], low[1] - rge/2) COLOURED(10, 255, 10)
direction = 1
ENDIF
IF direction > 0 THEN
BACKGROUNDCOLOR(10, 255, 10, 100)
ELSE
BACKGROUNDCOLOR(255, 10, 10, 100)
ENDIF
RETURNThe direction variable carries the last signal forward, so the background stays green or red until the next crossover.
Example 2, Highlight an overbought zone (Indicator)
// Tint the background when RSI is above 70
IF RSI[14] > 70 THEN
BACKGROUNDCOLOR(255, 200, 200, 120)
ENDIF
RETURNOnly the overbought bars are shaded, at partial opacity.
Example 3, Mark a session window (Indicator)
// Light blue background during the morning hours
IF OpenTime >= 090000 AND OpenTime < 120000 THEN
BACKGROUNDCOLOR(200, 220, 255, 100)
ENDIF
RETURNThe tint spans the bars inside the chosen time window.
Common errors and gotchas
- Indicator only.
BACKGROUNDCOLORhas no effect in ProScreener, ProOrder or ProBacktest. Keep it in a ProBuilder indicator. - Per bar, not once. It colours only the bar it runs on. To shade a run of bars, call it on each of them, usually through a condition.
- Alpha matters. A high alpha hides the price bars. Use a moderate value so candles stay visible.
- Carry the state. To keep a colour until the next signal, hold the bias in a variable, as in Example 1, rather than colouring only the signal bar.
Related instructions
FILLCOLOR, fills a drawn object rather than the whole background.COLOURED, sets the colour of lines and drawings.ColorBetween, shades the area between two series.DRAWARROWUP, an arrow that pairs with a background tint.DRAWARROWDOWN, an arrow that pairs with a background tint.DrawOnLastBarOnly, restricts other drawings to the last bar.IF, gates the colour on a condition.RETURN, ends the indicator after the drawing calls.
