Plot future dates

Viewed 316

I wrote a pinescript about vertical line for each specific date using histogram.

PineScript

//@version=4
study("Plot vertical line with date", overlay=true)
plot((time == timestamp("GMT+0", 2021,11,11,0,0)) ? 100000 : na, color = color.rgb(255, 0, 0, 22), linewidth = 1, title = "Happy 11:11", style =  plot.style_histogram)
plot((time == timestamp("GMT+0", 2022,1,1,0,0)) ? 100000 : na, color = color.rgb(255, 0, 0, 22), linewidth = 1, title = "Happy New Year 2022", style =  plot.style_histogram)

Problem

When I set future date (1 January 2022) with plot function, the pinescript run successfully but doesn't show in the chart.

2 Answers

You can draw vertical lines in the future using line.new(). This script also allows you to change the date in the script's inputs:

//@version=4
study("Plot vertical line with date", overlay=true)
t1 = input(timestamp("2021-11-23T00:00:00+00:00"), "Date", type = input.time)
if barstate.islast
    line.new(t1, 0, t1, 1, xloc = xloc.bar_time, extend = extend.both)

enter image description here

You can't plot in the future, you'll need to use the offset argument as a workaround.

Related