Skip to content
Algo Trade Analytics Docs

box.set_bgcolor() - Pine Script Function

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.

box.set_bgcolor(id, color) → void
NameTypeDescription
idseries boxThe box object to update.
colorseries colorThe new background color.
//@version=6
indicator("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))
  • 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.