Skip to content

chart.point ​

How do you name a place on the chart once and hand it to any drawing? Make a chart.point: it holds a bar index, a time and a price, and label.new, line.new, box.new and polyline.new each take one in place of separate x and y arguments.

pine
//@version=6
indicator("A week of closes", overlay = true)
if barstate.islast
    // The same two points serve the line and the label.
    a = chart.point.from_index(bar_index - 7, close[7])
    b = chart.point.now(close)
    line.new(a, b, color = color.orange, style = line.style_arrow_right)
    label.new(b, str.tostring(close - close[7], format.mintick),
          style = label.style_label_left)

A drawing reads a point by its own xloc: the point's index under xloc.bar_index, its time under xloc.bar_time. Left out, a drawing's xloc follows its first point, so one made by chart.point.from_time places by time. A drawing placed at a bar before the one that made it, such as a point at bar_index - 7, runs with a leak warning: on the chart it looks known earlier than it was.

A field can't be written here

p.price := 5 runs without an error and leaves p as it was. On TradingView it changes the point. Make a new point instead: p := chart.point.from_index(p.index, 5).

chart.point ​

The type of a point, with three fields: index, the bar index; time, the bar's time in milliseconds; and price. A field the point was made without reads na.

This engine also reads x as the index, or the time on a point made by time, and y as the price. TradingView has neither, so a script that reads them runs only here.

chart.point.new ​

pine
chart.point.new(time, index, price) → chart.point

A point with all three fields given.

ParameterDescription
time
series int
The time in milliseconds.
index
series int
The bar index.
price
series int/float
The price.

chart.point.now ​

pine
chart.point.now(price) → chart.point

A point on the current bar: its time, its bar index and price.

ParameterDefaultDescription
price
series int/float
closeThe price.

chart.point.from_index ​

pine
chart.point.from_index(index, price) → chart.point

A point at a bar index. Its time is na.

ParameterDescription
index
series int
The bar index.
price
series int/float
The price.

chart.point.from_time ​

pine
chart.point.from_time(time, price) → chart.point

A point at a time. Its index is na.

ParameterDescription
time
series int
The time in milliseconds.
price
series int/float
The price.

chart.point.copy ​

pine
chart.point.copy(id) → chart.point

Also a method: id.copy().

A new point with the same fields.

ParameterDescription
id
chart.point
The point to copy.

See also ​

AmenoScript is compatible with Pine Script v6. Pine Script is a trademark of TradingView, Inc., which has no part in AmenoScript.