Sidechair

line.set_xy2()

Browse the reference

Relocates the end of a line to a new bar and price in one call.

Try it in the editor

Calling line.set_xy2(ln, bar_index, close) each bar makes the right end track the live price while the left end stays anchored, like a rubber band.

A line created with equal x values is a vertical stub until this call gives the second point a different bar.

Syntax

Pine Script
line.set_xy2(id: series line, x: series int, y: series int/float) -> void
line.set_xy2(x: series int, y: series int/float) -> void

Arguments

NameTypeDefaultDescription
idseries linerequiredThe line whose second point is moved; the first point stays anchored.
xseries intrequiredBar index, or millisecond timestamp on a bar_time line, of the new second point.
yseries int/floatrequiredPrice of the new second point, in chart price units.

Returns

Nothing.

Example

Pine ScriptRubber band from the session open to the closeOpen in editor
//@version=6
indicator("line.set_xy2: live rubber band", overlay = true)
var line ln = na
if timeframe.change("D")
    ln := line.new(bar_index, open, bar_index, close, color = color.blue)
line.set_xy2(ln, bar_index, close)

See also

Runs on Sidechair