Skip to content

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 label

Makes 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.

ParameterDefaultDescription
x
series int
The bar, as a bar index, or a time in milliseconds under xloc.bar_time.
y
series int/float
The price.
text
series string
""The words. \n starts a new line.
xloc
series string
xloc.bar_indexWhether x is a bar index or a time.
yloc
series string
yloc.priceyloc.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.
color
series color
color.blueThe label's fill, or the shape's colour.
style
series string
label.style_label_downThe shape. See label.style_*.
textcolor
series color
color.whiteThe text's colour.
size
series string
size.normalThe size of the label and its text, from size.tiny to size.huge.
textalign
series string
text.align_centerHow lines of text line up inside the label: text.align_left, text.align_center or text.align_right.
tooltip
series string
""Words shown while the pointer is over the label.
text_font_family
series string
font.family_defaultfont.family_default or font.family_monospace.
force_overlay
const bool
falsetrue draws on the price pane even from a script with a pane of its own.
text_formatting
const string
text.format_nonetext.format_bold, text.format_italic, or both added together.
point
chart.point
A chart.point that gives the bar and the price.

label.copy ​

pine
label.copy(id) → series label

Also a method: id.copy().

A new label with every value of id. A deleted label copies too, and the copy is on the chart.

ParameterDescription
id
series label
The label to copy.

label.delete ​

pine
label.delete(id) → void

Also a method: id.delete().

Takes the label off the chart and out of label.all.

ParameterDescription
id
series label
The label.

label.all ​

pine
array<label> label.all

An 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 int

Also a method: id.get_x().

The label's bar index, or its time under xloc.bar_time.

ParameterDescription
id
series label
The label.

label.get_y ​

pine
label.get_y(id) → series float

Also a method: id.get_y().

The label's price.

ParameterDescription
id
series label
The label.

label.get_text ​

pine
label.get_text(id) → series string

Also a method: id.get_text().

The label's text. A deleted label reads "", not na.

ParameterDescription
id
series label
The label.

label.set_x ​

pine
label.set_x(id, x) → void

Also a method: id.set_x(x).

Moves the label to another bar.

ParameterDescription
id
series label
The label.
x
series int
The bar index, or the time under xloc.bar_time.

label.set_y ​

pine
label.set_y(id, y) → void

Also a method: id.set_y(y).

Moves the label to another price.

ParameterDescription
id
series label
The label.
y
series int/float
The price.

label.set_xy ​

pine
label.set_xy(id, x, y) → void

Also a method: id.set_xy(x, y).

Moves the label to another bar and price.

ParameterDescription
id
series label
The label.
x
series int
The bar index, or the time under xloc.bar_time.
y
series int/float
The price.

label.set_point ​

pine
label.set_point(id, point) → void

Also a method: id.set_point(point).

Moves the label to a point, read by the label's own xloc.

ParameterDescription
id
series label
The label.
point
chart.point
The chart.point.

label.set_xloc ​

pine
label.set_xloc(id, x, xloc) → void

Also 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.

ParameterDescription
id
series label
The label.
x
series int
The bar index or time.
xloc
series string
xloc.bar_index or xloc.bar_time.

label.set_yloc ​

pine
label.set_yloc(id, yloc) → void

Also a method: id.set_yloc(yloc).

Sets whether the label sits at its price, above the bar's high or below its low.

ParameterDescription
id
series label
The label.
yloc
series string
yloc.price, yloc.abovebar or yloc.belowbar.

label.set_text ​

pine
label.set_text(id, text) → void

Also a method: id.set_text(text).

Replaces the label's text.

ParameterDescription
id
series label
The label.
text
series string
The words.

label.set_color ​

pine
label.set_color(id, color) → void

Also a method: id.set_color(color).

Sets the label's fill, or its shape's colour.

ParameterDescription
id
series label
The label.
color
series color
The colour. na leaves no fill.

label.set_textcolor ​

pine
label.set_textcolor(id, textcolor) → void

Also a method: id.set_textcolor(textcolor).

Sets the text's colour.

ParameterDescription
id
series label
The label.
textcolor
series color
The colour.

label.set_style ​

pine
label.set_style(id, style) → void

Also a method: id.set_style(style).

Sets the label's shape.

ParameterDescription
id
series label
The label.
style
series string
A label.style_* value.

label.set_size ​

pine
label.set_size(id, size) → void

Also a method: id.set_size(size).

Sets the size of the label and its text.

ParameterDescription
id
series label
The label.
size
series string
size.tiny, size.small, size.normal, size.large, size.huge or size.auto.

label.set_textalign ​

pine
label.set_textalign(id, textalign) → void

Also a method: id.set_textalign(textalign).

Sets how lines of text line up inside the label.

ParameterDescription
id
series label
The label.
textalign
series string
text.align_left, text.align_center or text.align_right.

label.set_tooltip ​

pine
label.set_tooltip(id, tooltip) → void

Also a method: id.set_tooltip(tooltip).

Sets the words shown while the pointer is over the label.

ParameterDescription
id
series label
The label.
tooltip
series string
The words.

label.set_text_font_family ​

pine
label.set_text_font_family(id, text_font_family) → void

Also a method: id.set_text_font_family(text_font_family).

Sets the text's font.

ParameterDescription
id
series label
The label.
text_font_family
series string
font.family_default or font.family_monospace.

label.set_text_formatting ​

pine
label.set_text_formatting(id, text_formatting) → void

Also a method: id.set_text_formatting(text_formatting).

Sets the text to bold, italic, both or neither.

ParameterDescription
id
series label
The label.
text_formatting
const 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.

NameWhat it means
label.style_arrowdownAn arrow pointing down.
label.style_arrowupAn arrow pointing up.
label.style_circleA circle.
label.style_crossA plus sign.
label.style_diamondA diamond.
label.style_flagA flag.
label.style_label_centerA box centred on the point, with no tail.
label.style_label_downA box above the point, its tail down to it.
label.style_label_leftA box right of the point, its tail left to it.
label.style_label_lower_leftA box above and right of the point, its corner on it.
label.style_label_lower_rightA box above and left of the point, its corner on it.
label.style_label_rightA box left of the point, its tail right to it.
label.style_label_upA box below the point, its tail up to it.
label.style_label_upper_leftA box below and right of the point, its corner on it.
label.style_label_upper_rightA box below and left of the point, its corner on it.
label.style_noneThe text alone, written up from the point.
label.style_squareA square.
label.style_text_outlineThe text alone, centred on the point and outlined in color.
label.style_triangledownA triangle pointing down.
label.style_triangleupA triangle pointing up.
label.style_xcrossAn X.

See also ​

AmenoScript is compatible with Pine Script v6. Pine Script is a trademark of TradingView, Inc., which has no part in AmenoScript.