Sidechair

line.set_xloc()

Browse the reference

Rewrites both x values of a line and switches them between bar indexes and timestamps.

Try it in the editor

A bar index and a timestamp are different numbers, so x1, x2 and xloc go in together: line.set_xloc(ln, t1, t2, xloc.bar_time). The prices stay as they were.

A line placed by time keeps its moments when the chart changes timeframe; a line placed by index keeps its bar count.

Syntax

Pine Script
line.set_xloc(id: series line, x1: series int, x2: series int, xloc: series string) -> void
line.set_xloc(x1: series int, x2: series int, xloc: series string) -> void

Arguments

NameTypeDefaultDescription
idseries linerequiredThe line to re-express in another x scale; its prices are not touched.
x1series intrequiredNew x of the first point, written in the scale that xloc selects.
x2series intrequiredNew x of the second point, written in the scale that xloc selects.
xlocseries stringrequiredxloc.bar_index treats x1 and x2 as bar indexes; xloc.bar_time treats them as millisecond timestamps.

Returns

Nothing.

Remarks

  • On Sidechair: a timestamp that falls between bars lands on the next bar, and one after the last bar is placed ahead of it by the elapsed time measured in bar lengths of the chart's timeframe.

Example

Pine ScriptStub reaching five bars past the current barOpen in editor
//@version=6
indicator("line.set_xloc: project ahead", overlay = true)
var line ln = line.new(bar_index, close, bar_index + 1, close, color = color.fuchsia)
line.set_xloc(ln, time, time + 5 * timeframe.in_seconds() * 1000, xloc.bar_time)
line.set_y1(ln, close)
line.set_y2(ln, close + ta.atr(5))

See also

Runs on Sidechair