Future dates

Changed

You can colour a stretch of time, including time that has not happened yet. A future bar is drawn the same way as a past one.

Colour a zone#

Use bgcolor for a cycle, a session, or any other stretch of time. The colour fills the pane from top to bottom, at any zoom, including when you have dragged the price scale far above or below the candles. It does not move the price scale.

Paint bars that have not closed#

To colour bars ahead of the last close:

  1. Pick a fixed number of bars, n. It has to stay below the number of bars on the chart.
  2. Work out the length of one bar: barMs = timeframe.in_seconds(timeframe.period) * 1000.
  3. Call bgcolor(colorFor(time + n * barMs), offset = n) only where bar_index + n > last_bar_index.

The future bar takes the colour computed on bar j - n. n has to be a fixed number. If it changes from bar to bar, the paint will not line up.

plot(series, offset = n) and fill() between two such plots draw n bars ahead in the same way.

A line at a future time#

line.new, label.new, box.new, and polyline.new with xloc = xloc.bar_time take any time, including a future one. linefill.new fills between two of those lines.

A vertical line through the pane is:

text
line.new(t, close, t, close * 1.01, xloc = xloc.bar_time, extend = extend.both)

A fill between two price lines is a price range, not a full-height zone. A box is a price range too. Do not fake a full-height zone with a made-up top or bottom.

table.new can sit in any corner. A table at the top sits under the legend.

A worked example#

This colours one zone on history, and the same zone 300 bars ahead.

bullscript-run
1//@version=6
2indicator("Zones", overlay=true)
3AHEAD = 300
4barMs = timeframe.in_seconds(timeframe.period) * 1000
5zone(t) => t >= timestamp("UTC", 2027, 2, 1, 0, 0) and t < timestamp("UTC", 2028, 4, 15, 0, 0) ? color.new(color.gray, 75) : na
6bgcolor(zone(time), title="Zone")
7bgcolor(bar_index + AHEAD > last_bar_index ? zone(time + AHEAD * barMs) : na, offset=AHEAD, title="Zone ahead")
8plot(close)

Chart times are UTC.