Sidechair

label.get_text()

Browse the reference

Returns the text a label currently shows, so a script can test or extend it without a second string variable.

Try it in the editor

It reads back what label.new() or label.set_text() stored, line breaks included. A script can use the label as its own memory: branch on the stored words instead of keeping a parallel string.

The value is the text as of this moment in the bar, so a set_text call earlier in the same bar is already visible.

Syntax

Pine Script
label.get_text(id: series label) -> series string
label.get_text() -> series string

Arguments

NameTypeDefaultDescription
idseries labelrequiredThe label whose text is read back. Its text is not changed by the call.

Returns

series string: The label's text.

Remarks

  • On Sidechair: a label that is na gives na, and a label whose text was cleared gives an empty string.

Example

Pine ScriptFlip a state label on each crossOpen in editor
//@version=6
indicator("label.get_text: state flip", overlay = true)
var label state = label.new(bar_index, high, "long", style = label.style_label_down)
if ta.cross(close, ta.sma(close, 20))
    label.set_text(state, label.get_text(state) == "long" ? "short" : "long")
label.set_xy(state, bar_index, high)

See also

Runs on Sidechair