Appearance
box
How do you shade a range of bars and prices? Call box.new with its top-left and bottom-right corners: the left bar and top price, then the right bar and bottom price. Keep the handle to move the corners or change the text later.
pine
//@version=6
indicator("Last 20 bars' range", overlay = true)
hi = ta.highest(high, 20)
lo = ta.lowest(low, 20)
var box zone = box.new(na, na, na, na,
bgcolor = color.new(color.blue, 85), border_color = color.blue)
if barstate.islast
// Top-left corner, then bottom-right.
box.set_lefttop(zone, bar_index - 19, hi)
box.set_rightbottom(zone, bar_index, lo)
box.set_text(zone, str.tostring(hi - lo, format.mintick))A deleted box leaves the chart and box.all at once. Its getters read na and its setters do nothing. Past max_boxes_count + 5 boxes on the chart, the oldest go until max_boxes_count are left, 50 by default, as with labels. A drawing placed at a bar before the one that made it, such as bar_index - 5, runs with a leak warning: on the chart it looks known earlier than it was.
box.new
pine
box.new(left, top, right, bottom, border_color, border_width, border_style, extend, xloc, bgcolor, text, text_size, text_color, text_halign, text_valign, text_wrap, text_font_family, force_overlay, text_formatting) → series box
box.new(top_left, bottom_right, border_color, border_width, border_style, extend, xloc, bgcolor, text, text_size, text_color, text_halign, text_valign, text_wrap, text_font_family, force_overlay, text_formatting) → series boxMakes a box from its top-left corner to its bottom-right one, and returns its handle.
In the second form, two chart.points stand in for the corners. Left out there, xloc follows the first point: one made by chart.point.from_time places by time, any other by bar index.
The box's text is white unless text_color says otherwise. TradingView's manual says color.black, but TradingView draws white, and so does this engine.
| Parameter | Default | Description |
|---|---|---|
leftseries int | The left edge's bar, as a bar index, or a time in milliseconds under xloc.bar_time. | |
topseries int/float | The top edge's price. | |
rightseries int | The right edge's bar. | |
bottomseries int/float | The bottom edge's price. | |
border_colorseries color | color.blue | The border's colour. |
border_widthseries int | 1 | The border's width in pixels. |
border_styleseries string | line.style_solid | line.style_solid, line.style_dashed or line.style_dotted. |
extendseries string | extend.none | extend.left, extend.right or extend.both carry the box on to the chart's edge. |
xlocseries string | xloc.bar_index | Whether left and right are bar indexes or times. |
bgcolorseries color | color.blue | The fill. |
textseries string | "" | The words inside the box. \n starts a new line. |
text_sizeseries string | size.auto | size.auto fits the text to the box. size.tiny to size.huge fix it. |
text_colorseries color | color.white | The text's colour. |
text_halignseries string | text.align_center | text.align_left, text.align_center or text.align_right. |
text_valignseries string | text.align_center | text.align_top, text.align_center or text.align_bottom. |
text_wrapseries string | text.wrap_none | text.wrap_auto wraps the text to the box's width. |
text_font_familyseries string | font.family_default | font.family_default or font.family_monospace. |
force_overlayconst bool | false | true draws on the price pane even from a script with a pane of its own. |
text_formattingconst string | text.format_none | text.format_bold, text.format_italic, or both added together. |
top_leftchart.point | A chart.point for the top-left corner. | |
bottom_rightchart.point | A chart.point for the bottom-right corner. |
box.copy
pine
box.copy(id) → series boxAlso a method: id.copy().
A new box with every value of id. A deleted box copies too, and the copy is on the chart.
| Parameter | Description |
|---|---|
idseries box | The box to copy. |
box.delete
pine
box.delete(id) → voidAlso a method: id.delete().
Takes the box off the chart and out of box.all.
| Parameter | Description |
|---|---|
idseries box | The box. |
box.all
pine
array<box> box.allAn array of every box the script has on the chart, oldest first. A deleted box, or one the count took, isn't in it.
box.get_left
pine
box.get_left(id) → series intAlso a method: id.get_left().
The left edge's bar index, or its time under xloc.bar_time.
| Parameter | Description |
|---|---|
idseries box | The box. |
box.get_right
pine
box.get_right(id) → series intAlso a method: id.get_right().
The right edge's bar index, or its time under xloc.bar_time.
| Parameter | Description |
|---|---|
idseries box | The box. |
box.get_top
pine
box.get_top(id) → series floatAlso a method: id.get_top().
The top edge's price.
| Parameter | Description |
|---|---|
idseries box | The box. |
box.get_bottom
pine
box.get_bottom(id) → series floatAlso a method: id.get_bottom().
The bottom edge's price.
| Parameter | Description |
|---|---|
idseries box | The box. |
box.set_left
pine
box.set_left(id, left) → voidAlso a method: id.set_left(left).
Moves the left edge to another bar.
| Parameter | Description |
|---|---|
idseries box | The box. |
leftseries int | The bar index, or the time under xloc.bar_time. |
box.set_right
pine
box.set_right(id, right) → voidAlso a method: id.set_right(right).
Moves the right edge to another bar.
| Parameter | Description |
|---|---|
idseries box | The box. |
rightseries int | The bar index, or the time under xloc.bar_time. |
box.set_top
pine
box.set_top(id, top) → voidAlso a method: id.set_top(top).
Moves the top edge to another price.
| Parameter | Description |
|---|---|
idseries box | The box. |
topseries int/float | The price. |
box.set_bottom
pine
box.set_bottom(id, bottom) → voidAlso a method: id.set_bottom(bottom).
Moves the bottom edge to another price.
| Parameter | Description |
|---|---|
idseries box | The box. |
bottomseries int/float | The price. |
box.set_lefttop
pine
box.set_lefttop(id, left, top) → voidAlso a method: id.set_lefttop(left, top).
Moves the top-left corner.
| Parameter | Description |
|---|---|
idseries box | The box. |
leftseries int | The bar index, or the time under xloc.bar_time. |
topseries int/float | The price. |
box.set_rightbottom
pine
box.set_rightbottom(id, right, bottom) → voidAlso a method: id.set_rightbottom(right, bottom).
Moves the bottom-right corner.
| Parameter | Description |
|---|---|
idseries box | The box. |
rightseries int | The bar index, or the time under xloc.bar_time. |
bottomseries int/float | The price. |
box.set_top_left_point
pine
box.set_top_left_point(id, point) → voidAlso a method: id.set_top_left_point(point).
Moves the top-left corner to a point, read by the box's own xloc.
| Parameter | Description |
|---|---|
idseries box | The box. |
pointchart.point | The chart.point. |
box.set_bottom_right_point
pine
box.set_bottom_right_point(id, point) → voidAlso a method: id.set_bottom_right_point(point).
Moves the bottom-right corner to a point, read by the box's own xloc.
| Parameter | Description |
|---|---|
idseries box | The box. |
pointchart.point | The chart.point. |
box.set_xloc
pine
box.set_xloc(id, left, right, xloc) → voidAlso a method: id.set_xloc(left, right, xloc).
Sets both edges' bars and whether they're bar indexes or times, together.
| Parameter | Description |
|---|---|
idseries box | The box. |
leftseries int | The left edge's bar index or time. |
rightseries int | The right edge's bar index or time. |
xlocseries string | xloc.bar_index or xloc.bar_time. |
box.set_extend
pine
box.set_extend(id, extend) → voidAlso a method: id.set_extend(extend).
Sets whether the box carries on to the chart's edge.
| Parameter | Description |
|---|---|
idseries box | The box. |
extendseries string | extend.none, extend.left, extend.right or extend.both. |
box.set_border_color
pine
box.set_border_color(id, color) → voidAlso a method: id.set_border_color(color).
Sets the border's colour.
| Parameter | Description |
|---|---|
idseries box | The box. |
colorseries color | The colour. |
box.set_border_width
pine
box.set_border_width(id, width) → voidAlso a method: id.set_border_width(width).
Sets the border's width.
| Parameter | Description |
|---|---|
idseries box | The box. |
widthseries int | The width in pixels. |
box.set_border_style
pine
box.set_border_style(id, style) → voidAlso a method: id.set_border_style(style).
Sets the border's style.
| Parameter | Description |
|---|---|
idseries box | The box. |
styleseries string | line.style_solid, line.style_dashed or line.style_dotted. |
box.set_bgcolor
pine
box.set_bgcolor(id, color) → voidAlso a method: id.set_bgcolor(color).
Sets the fill.
| Parameter | Description |
|---|---|
idseries box | The box. |
colorseries color | The colour. |
box.set_text
pine
box.set_text(id, text) → voidAlso a method: id.set_text(text).
Replaces the text inside the box.
| Parameter | Description |
|---|---|
idseries box | The box. |
textseries string | The words. |
box.set_text_color
pine
box.set_text_color(id, text_color) → voidAlso a method: id.set_text_color(text_color).
Sets the text's colour.
| Parameter | Description |
|---|---|
idseries box | The box. |
text_colorseries color | The colour. |
box.set_text_size
pine
box.set_text_size(id, text_size) → voidAlso a method: id.set_text_size(text_size).
Sets the text's size.
| Parameter | Description |
|---|---|
idseries box | The box. |
text_sizeseries string | size.auto, or size.tiny to size.huge. |
box.set_text_halign
pine
box.set_text_halign(id, text_halign) → voidAlso a method: id.set_text_halign(text_halign).
Sets the text's place across the box.
| Parameter | Description |
|---|---|
idseries box | The box. |
text_halignseries string | text.align_left, text.align_center or text.align_right. |
box.set_text_valign
pine
box.set_text_valign(id, text_valign) → voidAlso a method: id.set_text_valign(text_valign).
Sets the text's place up and down the box.
| Parameter | Description |
|---|---|
idseries box | The box. |
text_valignseries string | text.align_top, text.align_center or text.align_bottom. |
box.set_text_wrap
pine
box.set_text_wrap(id, text_wrap) → voidAlso a method: id.set_text_wrap(text_wrap).
Sets whether the text wraps to the box's width.
| Parameter | Description |
|---|---|
idseries box | The box. |
text_wrapseries string | text.wrap_none or text.wrap_auto. |
box.set_text_font_family
pine
box.set_text_font_family(id, text_font_family) → voidAlso a method: id.set_text_font_family(text_font_family).
Sets the text's font.
| Parameter | Description |
|---|---|
idseries box | The box. |
text_font_familyseries string | font.family_default or font.family_monospace. |
box.set_text_formatting
pine
box.set_text_formatting(id, text_formatting) → voidAlso a method: id.set_text_formatting(text_formatting).
Sets the text to bold, italic, both or neither.
| Parameter | Description |
|---|---|
idseries box | The box. |
text_formattingconst string | text.format_none, text.format_bold, text.format_italic, or bold and italic added together. |
See also
- chart.point
- label and line
- Drawings
- declarations, for
max_boxes_count