Reputation: 124
I'm trying to plot a vertical line using custom date from array.
What I'm trying to code is iterate all values using a for loop, and then plotting a vertical line, with a span of 1 futures day. That's the main target.
The code looks like that:
//@version=5
indicator('VertLine_Test', overlay=true)
start_date = array.from("2022-12-26 15:15","2023-01-05 01:45","2023-01-10 16:30") // and so on
// Iterate array
counter = -1
for i=-1 to array.size(start_date)
counter := i
counter := counter -1 // assign index Array
string_date = array.get(start_date,counter) // get the value based on index -> return Ex.2023-01-10 16:30
// Draw VerticalLine
drawVerticalLine(targetTime) =>
line.new(x1=targetTime, y1=low, x2=targetTime, y2=high, xloc=xloc.bar_time, extend=extend.both, color=color.new(#ea5e50, 10), style=line.style_solid, width=2)
targetTime = timestamp(string_date) // Assign value and convert to Timestamp
drawVerticalLine(targetTime) // Call function for draws Vertical Line
Now when I run the code, I get an error like this:
Compilation error. Cannot call 'timestamp' with argument 'dateString'='string_date'. An argument of 'series string' type was used but a 'const string' is expected
I'm struggle with that. What's could be the solution?
Upvotes: 1
Views: 344
Reputation: 2161
The issue is that timestamp()
can't take a series string
as an argument, but needs a constant string
(a string
that can't be changed during execution).
You can fix this by making an array of timestamp
instead of array of strings.
//@version=5
indicator("My script", overlay = true)
start_date = array.from(timestamp("2022-12-26 15:15"),timestamp("2023-01-05 01:45"),timestamp("2023-01-10 16:30")) // and so on
for date in start_date
line.new(x1=date, y1=low, x2=date, y2=high, xloc=xloc.bar_time, extend=extend.both, color=color.new(#ea5e50, 10), style=line.style_solid, width=2)
Upvotes: 3