Sidechair

line.get_price()

Browse the reference

Evaluates the straight line through two points at any bar and returns its price there.

Try it in the editor

The line is treated as running forever in both directions, so the answer is defined for any x, even one beyond the drawn segment or before it. At x1 it equals the first price and at x2 the second, with a straight-line step between and beyond.

A vertical line, whose two x values are equal, has no single price at x and returns na. A na line returns na as well.

Syntax

Pine Script
line.get_price(id: series line, x: series int) -> series float
line.get_price(x: series int) -> series float

Arguments

NameTypeDefaultDescription
idseries linerequiredThe line to read the price from; it is treated as infinite, so x may lie outside its segment.
xseries intrequiredBar index, or a millisecond timestamp for a line placed with xloc.bar_time, at which to evaluate the line.

Returns

series float: The price of the line at x.

Remarks

  • On Sidechair: the extend setting does not change the answer, so a line with extend.none still reports prices outside its segment.

Example

Pine ScriptWhere is the trendline nowOpen in editor
//@version=6
indicator("line.get_price: trend level", overlay = true)
var line trend = line.new(0, 0, 1, 1)
if bar_index == 100
    trend := line.new(bar_index - 50, close[50], bar_index, close, extend = extend.right)
plot(bar_index > 100 ? line.get_price(trend, bar_index) : na, "Trendline price")

See also

Runs on Sidechair