Sidechair

line.get_y2()

Browse the reference

Returns the price stored for the second end point of a line.

Try it in the editor

Pair it with line.get_y1() and the two x getters to get the slope: the rise divided by the number of bars between the points. The value is the one given at creation or the last time the second point moved.

For an extended line it is still the stored price at the second point, and line.get_price() at line.get_x2() returns the same number unless the line is vertical.

Syntax

Pine Script
line.get_y2(id: series line) -> series float
line.get_y2() -> series float

Arguments

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

Returns

series float: The y coordinate of the second point.

Example

Pine ScriptSlope per bar of the latest segmentOpen in editor
//@version=6
indicator("line.get_y2: slope per bar", overlay = false)
var line ln = na
if bar_index > 10 and bar_index % 50 == 0
    ln := line.new(bar_index - 10, low[10], bar_index, high)
plot(na(ln) ? na : (line.get_y2(ln) - line.get_y1(ln)) / (line.get_x2(ln) - line.get_x1(ln)), "Slope per bar")

See also

Runs on Sidechair