Sidechair

box.set_text_halign()

Browse the reference

Sets where text sits across a box's width: against the left edge, in the middle or against the right edge.

Try it in the editor

text.align_left puts the text against the left border, text.align_right against the right, and text.align_center in the middle. It only has an effect when the box is wider than its text.

A right-aligned value in a wide box reads like a price tag attached to the right side of the zone.

Syntax

Pine Script
box.set_text_halign(id: series box, text_halign: series string) -> void
box.set_text_halign(text_halign: series string) -> void

Arguments

NameTypeDefaultDescription
idseries boxrequiredThe box whose horizontal text position changes.
text_halignseries stringrequiredtext.align_left, text.align_center (default) or text.align_right. It has an effect only when the box is wider than its text.

Returns

Nothing.

Remarks

  • On Sidechair: alignment is not applied yet. A call reports a warning and the text stays centred.
  • On Sidechair: calling it as z.set_text_halign(...) stops the script with an error instead of a warning, so write box.set_text_halign(z, ...).

Example

Pine ScriptRight-aligned price in a wide boxOpen in editor
//@version=6
indicator("box.set_text_halign: right-aligned price", overlay = true)
if barstate.islast
    z = box.new(bar_index - 40, high, bar_index, low, bgcolor = color.new(color.gray, 88), text = str.tostring(close, "#.##"), text_color = color.white)
    box.set_text_halign(z, text.align_right)

See also

Not on Sidechair yet