box.set_bgcolor() - Pine Script Function
Overview
Section titled “Overview”Sets the background color of an existing box. Use color.new() when the fill
should be translucent, or pass na to make the background invisible.
Syntax
Section titled “Syntax”box.set_bgcolor(id, color) → voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
id | series box | The box object to update. |
color | series color | The new background color. |
Minimal example
Section titled “Minimal example”//@version=6indicator("Box background", overlay = true, max_boxes_count = 10)
var box rangeBox = na
if barstate.isfirst rangeBox := box.new(bar_index, high, bar_index + 5, low)
if not na(rangeBox) box.set_bgcolor(rangeBox, color.new(color.orange, 80))Remarks
Section titled “Remarks”- The function changes only the fill. Use the
box.set_border_*()functions to change the border. - Reusing a box and updating its properties avoids creating a new drawing on every bar.