Appearance
label
How do you write text on the chart at a bar? Call label.new with a bar and a price, or with a chart.point, and keep the handle it returns to change the label later. Each call makes a new label, so a script that wants one label that follows the price makes it once with var and moves it.
pine
//@version=6
indicator("Last close", overlay = true)
// Made once, on the first bar, then moved:
// the chart holds one label, not one per bar.
var label tag = label.new(bar_index, close, "", style = label.style_label_left)
label.set_xy(tag, bar_index, close)
label.set_text(tag, str.tostring(close, format.mintick))A deleted label leaves the chart and label.all at once. Its getters read na and its setters do nothing. 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.
A label a bar keeps only the newest 50
Once a script has made max_labels_count + 5 labels that are still on the chart, the oldest go until max_labels_count are left: 50 unless indicator() or strategy() sets it. A label taken this way leaves the chart and label.all, but its getters still read it.
label.new
pine
label.new(x, y, text, xloc, yloc, color, style, textcolor, size, textalign, tooltip, text_font_family, force_overlay, text_formatting) → series label
label.new(point, text, xloc, yloc, color, style, textcolor, size, textalign, tooltip, text_font_family, force_overlay, text_formatting) → series labelMakes a label at a bar and a price, and returns its handle.
In the second form, a chart.point stands in for x and y. Left out there, xloc follows the point: one made by chart.point.from_time places by time, any other by bar index.
| Parameter | Default | Description |
|---|---|---|
xseries int | The bar, as a bar index, or a time in milliseconds under xloc.bar_time. | |
yseries int/float | The price. | |
textseries string | "" | The words. \n starts a new line. |
xlocseries string | xloc.bar_index | Whether x is a bar index or a time. |
ylocseries string | yloc.price | yloc.price puts the label at y. yloc.abovebar puts it above the bar's high and yloc.belowbar below its low, and both ignore y. |
colorseries color | color.blue | The label's fill, or the shape's colour. |
styleseries string | label.style_label_down | The shape. See label.style_*. |
textcolorseries color | color.white | The text's colour. |
sizeseries string | size.normal | The size of the label and its text, from size.tiny to size.huge. |
textalignseries string | text.align_center | How lines of text line up inside the label: text.align_left, text.align_center or text.align_right. |
tooltipseries string | "" | Words shown while the pointer is over the label. |
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. |
pointchart.point | A chart.point that gives the bar and the price. |
label.copy
pine
label.copy(id) → series labelAlso a method: id.copy().
A new label with every value of id. A deleted label copies too, and the copy is on the chart.
| Parameter | Description |
|---|---|
idseries label | The label to copy. |
label.delete
pine
label.delete(id) → voidAlso a method: id.delete().
Takes the label off the chart and out of label.all.
| Parameter | Description |
|---|---|
idseries label | The label. |
label.all
pine
array<label> label.allAn array of every label the script has on the chart, oldest first. A deleted label, or one the count took, isn't in it.
label.get_x
pine
label.get_x(id) → series intAlso a method: id.get_x().
The label's bar index, or its time under xloc.bar_time.
| Parameter | Description |
|---|---|
idseries label | The label. |
label.get_y
pine
label.get_y(id) → series floatAlso a method: id.get_y().
The label's price.
| Parameter | Description |
|---|---|
idseries label | The label. |
label.get_text
pine
label.get_text(id) → series stringAlso a method: id.get_text().
The label's text. A deleted label reads "", not na.
| Parameter | Description |
|---|---|
idseries label | The label. |
label.set_x
pine
label.set_x(id, x) → voidAlso a method: id.set_x(x).
Moves the label to another bar.
| Parameter | Description |
|---|---|
idseries label | The label. |
xseries int | The bar index, or the time under xloc.bar_time. |
label.set_y
pine
label.set_y(id, y) → voidAlso a method: id.set_y(y).
Moves the label to another price.
| Parameter | Description |
|---|---|
idseries label | The label. |
yseries int/float | The price. |
label.set_xy
pine
label.set_xy(id, x, y) → voidAlso a method: id.set_xy(x, y).
Moves the label to another bar and price.
| Parameter | Description |
|---|---|
idseries label | The label. |
xseries int | The bar index, or the time under xloc.bar_time. |
yseries int/float | The price. |
label.set_point
pine
label.set_point(id, point) → voidAlso a method: id.set_point(point).
Moves the label to a point, read by the label's own xloc.
| Parameter | Description |
|---|---|
idseries label | The label. |
pointchart.point | The chart.point. |
label.set_xloc
pine
label.set_xloc(id, x, xloc) → voidAlso a method: id.set_xloc(x, xloc).
Sets the bar and whether it's a bar index or a time, together, so the two never disagree.
| Parameter | Description |
|---|---|
idseries label | The label. |
xseries int | The bar index or time. |
xlocseries string | xloc.bar_index or xloc.bar_time. |
label.set_yloc
pine
label.set_yloc(id, yloc) → voidAlso a method: id.set_yloc(yloc).
Sets whether the label sits at its price, above the bar's high or below its low.
| Parameter | Description |
|---|---|
idseries label | The label. |
ylocseries string | yloc.price, yloc.abovebar or yloc.belowbar. |
label.set_text
pine
label.set_text(id, text) → voidAlso a method: id.set_text(text).
Replaces the label's text.
| Parameter | Description |
|---|---|
idseries label | The label. |
textseries string | The words. |
label.set_color
pine
label.set_color(id, color) → voidAlso a method: id.set_color(color).
Sets the label's fill, or its shape's colour.
| Parameter | Description |
|---|---|
idseries label | The label. |
colorseries color | The colour. na leaves no fill. |
label.set_textcolor
pine
label.set_textcolor(id, textcolor) → voidAlso a method: id.set_textcolor(textcolor).
Sets the text's colour.
| Parameter | Description |
|---|---|
idseries label | The label. |
textcolorseries color | The colour. |
label.set_style
pine
label.set_style(id, style) → voidAlso a method: id.set_style(style).
Sets the label's shape.
| Parameter | Description |
|---|---|
idseries label | The label. |
styleseries string | A label.style_* value. |
label.set_size
pine
label.set_size(id, size) → voidAlso a method: id.set_size(size).
Sets the size of the label and its text.
| Parameter | Description |
|---|---|
idseries label | The label. |
sizeseries string | size.tiny, size.small, size.normal, size.large, size.huge or size.auto. |
label.set_textalign
pine
label.set_textalign(id, textalign) → voidAlso a method: id.set_textalign(textalign).
Sets how lines of text line up inside the label.
| Parameter | Description |
|---|---|
idseries label | The label. |
textalignseries string | text.align_left, text.align_center or text.align_right. |
label.set_tooltip
pine
label.set_tooltip(id, tooltip) → voidAlso a method: id.set_tooltip(tooltip).
Sets the words shown while the pointer is over the label.
| Parameter | Description |
|---|---|
idseries label | The label. |
tooltipseries string | The words. |
label.set_text_font_family
pine
label.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 label | The label. |
text_font_familyseries string | font.family_default or font.family_monospace. |
label.set_text_formatting
pine
label.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 label | The label. |
text_formattingconst string | text.format_none, text.format_bold, text.format_italic, or bold and italic added together. |
label.style_*
Values for a label's style. The label_* styles are a box round the text, with a tail toward the point the style names. The others are a shape at the point, with the text above it.
Each is a const string.
| Name | What it means |
|---|---|
label. | An arrow pointing down. |
label. | An arrow pointing up. |
label. | A circle. |
label. | A plus sign. |
label. | A diamond. |
label. | A flag. |
label. | A box centred on the point, with no tail. |
label. | A box above the point, its tail down to it. |
label. | A box right of the point, its tail left to it. |
label. | A box above and right of the point, its corner on it. |
label. | A box above and left of the point, its corner on it. |
label. | A box left of the point, its tail right to it. |
label. | A box below the point, its tail up to it. |
label. | A box below and right of the point, its corner on it. |
label. | A box below and left of the point, its corner on it. |
label. | The text alone, written up from the point. |
label. | A square. |
label. | The text alone, centred on the point and outlined in color. |
label. | A triangle pointing down. |
label. | A triangle pointing up. |
label. | An X. |
See also
- chart.point
- line and box
- table, for text that stays put on the screen
- Drawings
- declarations, for
max_labels_count