Sidechair

line.set_x2()

Browse the reference

Moves only the end of a line sideways, along the bar axis.

Try it in the editor

Calling it with bar_index each bar stretches the line along with the chart while the start stays fixed. Stop calling it and the line freezes at its last bar.

extend.right continues past the second point whichever side that point is on, so an x2 smaller than x1 sends a rightward extension toward the left of the chart.

Syntax

Pine Script
line.set_x2(id: series line, x: series int) -> void
line.set_x2(x: series int) -> void

Arguments

NameTypeDefaultDescription
idseries linerequiredThe line whose second point moves along the bar axis; the first point stays put.
xseries intrequiredNew bar index, or millisecond timestamp on a bar_time line, for the second point. It may be smaller than x1.

Returns

Nothing.

Example

Pine ScriptGrow a pivot level until price closes through itOpen in editor
//@version=6
indicator("line.set_x2: grow until broken", overlay = true)
ph = ta.pivothigh(high, 5, 5)
var line lvl = na
if not na(ph)
    lvl := line.new(bar_index - 5, ph, bar_index, ph, color = color.orange)
if not na(lvl) and line.get_x2(lvl) == bar_index - 1 and close < line.get_y2(lvl)
    line.set_x2(lvl, bar_index)

See also

Runs on Sidechair