Appearance
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.pointA point with all three fields given.
| Parameter | Description |
|---|---|
timeseries int | The time in milliseconds. |
indexseries int | The bar index. |
priceseries int/float | The price. |
chart.point.now
pine
chart.point.now(price) → chart.pointA point on the current bar: its time, its bar index and price.
| Parameter | Default | Description |
|---|---|---|
priceseries int/float | close | The price. |
chart.point.from_index
pine
chart.point.from_index(index, price) → chart.pointA point at a bar index. Its time is na.
| Parameter | Description |
|---|---|
indexseries int | The bar index. |
priceseries int/float | The price. |
chart.point.from_time
pine
chart.point.from_time(time, price) → chart.pointA point at a time. Its index is na.
| Parameter | Description |
|---|---|
timeseries int | The time in milliseconds. |
priceseries int/float | The price. |
chart.point.copy
pine
chart.point.copy(id) → chart.pointAlso a method: id.copy().
A new point with the same fields.
| Parameter | Description |
|---|---|
idchart.point | The point to copy. |