text

The text namespace provides constants for controlling text alignment, formatting, and wrapping in visual drawing objects such as labels, boxes, and table cells.

Quick Example

from pynecore.lib import script, label, text, bar_index, high, low, close, ta

@script.indicator(title="Signal Labels", overlay=True)
def main():
    is_cross: bool = ta.crossover(close, ta.sma(close, 20))
    if is_cross:
        label.new(
            bar_index, high,
            text="BUY",
            textalign=text.align_center,
            style=label.style_label_up,
            text_formatting=text.format_bold
        )

Constants

Alignment

ConstantDescription
text.align_leftAligns text to the left horizontally
text.align_centerCenters text horizontally or vertically
text.align_rightAligns text to the right horizontally
text.align_topAligns text to the top vertically
text.align_bottomAligns text to the bottom vertically

Horizontal alignment constants (align_left, align_center, align_right) are used with the textalign parameter of label.new() and label.set_textalign(), and the text_halign parameter of box.new() and box.set_text_halign().

Vertical alignment constants (align_top, align_center, align_bottom) are used with the text_valign parameter of box.new(), box.set_text_valign(), table.cell(), and table.cell_set_text_valign().

Formatting

ConstantDescription
text.format_boldRenders text in bold
text.format_italicRenders text in italic
text.format_noneNo special formatting (default)

Used with the text_formatting parameter of label.new(), box.new(), table.cell(), and their corresponding *set_text_formatting() functions.

Wrapping

ConstantDescription
text.wrap_autoText wraps automatically to fit within the object’s bounds
text.wrap_noneText wrapping is disabled; text overflows if too long

Used with the text_wrap parameter of box.new() and box.set_text_wrap().