label

Chart labels — create, modify, and style text labels on the chart.

Quick Example

  from pynecore.lib import (
    close, high, low, bar_index, label, color, xloc, yloc
)
from pynecore.types import Persistent

@script.indicator(title="Label Example", overlay=True)
def main():
    # Create a label at current bar
    lbl: Persistent[label] = label.new(
        bar_index,
        high,
        text="Peak",
        color=color.red,
        style=label.style_label_up,
        textcolor=color.white
    )
    
    # Modify label properties
    label.set_text(lbl, "New Text")
    label.set_color(lbl, color.blue)
    label.set_y(lbl, low)
  

Functions

label.new()

Creates a new label object on the chart.

Overload 1: With coordinates

  lbl: label = label.new(
    x: int,
    y: int | float,
    text: str = "",
    xloc: xloc = xloc.bar_index,
    yloc: yloc = yloc.price,
    color: color = color.blue,
    style: label_style = label.style_label_down,
    textcolor: color = color.white,
    size: size = size.normal,
    textalign: text_align = text_align.center,
    tooltip: str = "",
    force_overlay: bool = False
) → label
  
ParameterTypeDescription
xintBar index (if xloc=xloc.bar_index) or UNIX timestamp (if xloc=xloc.bar_time)
yint | floatPrice level (used only if yloc=yloc.price)
textstrLabel text (default: “”)
xlocxlocCoordinate mode: xloc.bar_index or xloc.bar_time
ylocylocVertical positioning: yloc.price, yloc.abovebar, or yloc.belowbar
colorcolorBorder and arrow color (default: blue)
stylelabel_styleVisual style (default: label.style_label_down)
textcolorcolorText color (default: white)
sizesizeText/arrow size: size.tiny, size.small, size.normal, size.large (default: normal)
textaligntext_alignAlignment: text_align.left, text_align.center, text_align.right
tooltipstrHover tooltip text (default: “”)
force_overlayboolIf true, display on main chart pane (default: false)

Overload 2: With chart.point

  lbl: label = label.new(
    point: chart.point,
    text: str = "",
    xloc: xloc = xloc.bar_index,
    yloc: yloc = yloc.price,
    color: color = color.blue,
    style: label_style = label.style_label_down,
    textcolor: color = color.white,
    size: size = size.normal,
    textalign: text_align = text_align.center,
    tooltip: str = "",
    force_overlay: bool = False
) → label
  

Uses a chart.point object to specify position.

label.delete()

Deletes a label from the chart. If already deleted, does nothing.

  label.delete(id: label) → None
  
ParameterTypeDescription
idlabelLabel object to delete

label.copy()

Clones a label object with all current properties.

  lbl_copy: label = label.copy(id: label) → label
  
ParameterTypeDescription
idlabelLabel to clone

Returns: New label with same properties as the original.

label.get_text()

Returns the text of a label.

  txt: str = label.get_text(id: label) → str
  
ParameterTypeDescription
idlabelLabel object

Returns: The label’s text string.

label.get_x()

Returns the x-coordinate (bar index or UNIX time) of the label position.

  x: int = label.get_x(id: label) → int
  
ParameterTypeDescription
idlabelLabel object

Returns: Bar index (if xloc=xloc.bar_index) or UNIX timestamp in milliseconds (if xloc=xloc.bar_time).

label.get_y()

Returns the price level of the label position.

  y: float = label.get_y(id: label) → float
  
ParameterTypeDescription
idlabelLabel object

Returns: Price as floating-point value.

label.set_text()

Sets the text of a label.

  label.set_text(id: label, text: str) → None
  
ParameterTypeDescription
idlabelLabel object
textstrNew text value

label.set_x()

Sets the x-coordinate (bar index or time) of the label position.

  label.set_x(id: label, x: int) → None
  
ParameterTypeDescription
idlabelLabel object
xintNew bar index or UNIX timestamp (milliseconds)

label.set_y()

Sets the price level of the label position.

  label.set_y(id: label, y: int | float) → None
  
ParameterTypeDescription
idlabelLabel object
yint | floatNew price level

label.set_xy()

Sets both x and y coordinates of the label position.

  label.set_xy(id: label, x: int, y: int | float) → None
  
ParameterTypeDescription
idlabelLabel object
xintNew bar index or UNIX timestamp (milliseconds)
yint | floatNew price level

Example:

  label.set_xy(lbl, bar_index + 1, high + 10)  # Move label
  

label.set_color()

Sets the border and arrow color of a label.

  label.set_color(id: label, color: color) → None
  
ParameterTypeDescription
idlabelLabel object
colorcolorNew color value

label.set_textcolor()

Sets the text color of a label.

  label.set_textcolor(id: label, textcolor: color) → None
  
ParameterTypeDescription
idlabelLabel object
textcolorcolorNew text color

label.set_size()

Sets the size of the label text and arrow symbol.

  label.set_size(id: label, size: size) → None
  
ParameterTypeDescription
idlabelLabel object
sizesizeNew size: size.tiny, size.small, size.normal, or size.large

label.set_style()

Sets the visual style of the label.

  label.set_style(id: label, style: label_style) → None
  
ParameterTypeDescription
idlabelLabel object
stylelabel_styleNew style constant (e.g., label.style_label_up)

label.set_textalign()

Sets the text alignment within the label.

  label.set_textalign(id: label, textalign: text_align) → None
  
ParameterTypeDescription
idlabelLabel object
textaligntext_alignAlignment: text_align.left, text_align.center, or text_align.right

label.set_tooltip()

Sets the hover tooltip text for a label.

  label.set_tooltip(id: label, tooltip: str) → None
  
ParameterTypeDescription
idlabelLabel object
tooltipstrTooltip text to display on hover

label.set_yloc()

Sets the y-location calculation mode for the label position.

  label.set_yloc(id: label, yloc: yloc) → None
  
ParameterTypeDescription
idlabelLabel object
ylocylocMode: yloc.price, yloc.abovebar, or yloc.belowbar

Variables

label.all

Returns an array of all label objects currently drawn by the script.

  all_labels: list[label] = label.all  # list[label]
  

Constants

All label style constants for use with label.new() and label.set_style():

ConstantStyle
label.style_noneNo visible shape
label.style_xcrossX-shaped cross
label.style_crossPlus-shaped cross
label.style_triangleupUpward-pointing triangle
label.style_triangledownDownward-pointing triangle
label.style_flagFlag marker
label.style_circleCircle
label.style_arrowupUpward-pointing arrow
label.style_arrowdownDownward-pointing arrow
label.style_label_upText label above the bar
label.style_label_downText label below the bar
label.style_label_leftText label to the left
label.style_label_rightText label to the right
label.style_label_upper_leftText label in upper-left corner
label.style_label_upper_rightText label in upper-right corner
label.style_label_lower_leftText label in lower-left corner
label.style_label_lower_rightText label in lower-right corner
label.style_label_centerText label centered
label.style_squareSquare shape
label.style_diamondDiamond shape
label.style_text_outlineText with outline

Compatibility

Not yet implemented:

  • label.set_point() — Not available
  • label.set_text_font_family() — Font family control not yet supported
  • label.set_text_formatting() — Text formatting (bold, italic) not yet supported
  • label.set_xloc() — Direct xloc changes not supported; use label.new() or label.set_x() instead