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

ConstantValueDescription
text.format_bold1Renders text in bold
text.format_italic2Renders text in italic
text.format_none0No special formatting (default)

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

Each style is one bit, the same values TradingView uses. A formatting value is a set of styles: + adds styles and - removes them, as set operations rather than integer arithmetic. Adding a style that is already in the set, or removing one that is not, leaves the set unchanged:

label.new(bar_index, high, "BUY", text_formatting=text.format_bold + text.format_italic)

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().