Sidechair

line.get_x2()

Browse the reference

Returns where a line ends on the x axis, as a bar index or a millisecond timestamp.

Try it in the editor

It is the stored second point. A line that extends to the right still reports the bar it was given, never the right edge of the chart.

Together with line.get_x1() it gives the width of the segment in bars. A na id yields na here too.

Syntax

Pine Script
line.get_x2(id: series line) -> series int
line.get_x2() -> series int

Arguments

NameTypeDefaultDescription
idseries linerequiredThe line to read the second point's x coordinate from.

Returns

series int: The x coordinate of the second point.

Example

Pine ScriptLength of a segment in barsOpen in editor
//@version=6
indicator("line.get_x2: segment length", overlay = false)
var line ln = line.new(0, 0, 1, 1)
if bar_index % 50 == 0
    ln := line.new(bar_index - 10, low, bar_index, high)
plot(line.get_x2(ln) - line.get_x1(ln), "Width in bars")

See also

Runs on Sidechair