How a drawing's x coordinate is read: xloc.bar_index counts bars, xloc.bar_time uses a UNIX time in milliseconds.
xloc.* constants go in the xloc argument of label.new, line.new and box.new. With xloc.bar_index (the default) the x value is a bar_index. With xloc.bar_time it is a time in milliseconds since 1970, such as time, time_close or a value from timestamp().
xloc.bar_time lets you anchor a drawing to a point in the future, past the last bar, where there is no bar_index yet: pass time plus a number of bars worth of milliseconds.
Constants
| Name | Value | Description |
|---|---|---|
xloc.bar_index | The x value is a bar index; the default. | |
xloc.bar_time | The x value is a UNIX time in milliseconds. |
Remarks
- Both x values of one line or box share a single xloc, so you cannot anchor one end by bar index and the other by time.
Example
//@version=6
indicator("Time anchor", overlay = true)
if barstate.islast
label.new(time, high, "last bar", xloc = xloc.bar_time, style = label.style_label_down, color = color.blue, textcolor = color.white)
line.new(time - 20 * 5 * 60 * 1000, low, time, low, xloc = xloc.bar_time, color = color.orange)
plot(close, "Close", color.gray)See also
Runs on Sidechair