I want to draw a vertical orange line on the 14th March 2025 @ 06:54 hrs
(I have numerous lines on varying timestamps that also need to be added)
I am using the code below to do this.
However, the line is always offset by 1 bar to the right on every time frame (apart from the 1 min chart)
It's my understanding that because I am using ".xloc.bar_time" that if my chart does not have a bar exactly at that timestamp, the line will offset to the next bar along (to the right)
So, my line is set to 14th March 2025 @ 06:54 hrs BUT
on Daily chart = line drawn on 15th (as opposed to 14th)
on 4 hr chart = line drawn at 08:00 (as opposed to 04:00)
on 1 hr chart = line drawn at 07:00 (as opposed to 06:00)
Is it possible to offset the line 1 bar to the left on all time frames?
Is there another workaround?
would using ".xloc.bar_index work" as I need to use a timestamp?
// Function drawVerticalLine
drawVerticalLine(targetTime) =>
line.new(
x1=targetTime,
y1=low,
x2=targetTime,
y2=high,
xloc=xloc.bar_time,
extend=extend.both,
color=color.new(#f9961e, 10),
style=line.style_solid,
width=1)
// Lines to Plot
targetTime = timestamp(2025,03,14,06,54,00)
drawVerticalLine(targetTime)
Daily Chart 4hr Chart 1hr Chart
I want to draw a vertical orange line on the 14th March 2025 @ 06:54 hrs
(I have numerous lines on varying timestamps that also need to be added)
I am using the code below to do this.
However, the line is always offset by 1 bar to the right on every time frame (apart from the 1 min chart)
It's my understanding that because I am using ".xloc.bar_time" that if my chart does not have a bar exactly at that timestamp, the line will offset to the next bar along (to the right)
So, my line is set to 14th March 2025 @ 06:54 hrs BUT
on Daily chart = line drawn on 15th (as opposed to 14th)
on 4 hr chart = line drawn at 08:00 (as opposed to 04:00)
on 1 hr chart = line drawn at 07:00 (as opposed to 06:00)
Is it possible to offset the line 1 bar to the left on all time frames?
Is there another workaround?
would using ".xloc.bar_index work" as I need to use a timestamp?
// Function drawVerticalLine
drawVerticalLine(targetTime) =>
line.new(
x1=targetTime,
y1=low,
x2=targetTime,
y2=high,
xloc=xloc.bar_time,
extend=extend.both,
color=color.new(#f9961e, 10),
style=line.style_solid,
width=1)
// Lines to Plot
targetTime = timestamp(2025,03,14,06,54,00)
drawVerticalLine(targetTime)
Daily Chart 4hr Chart 1hr Chart
Share Improve this question edited Apr 1 at 8:24 user30113140 asked Mar 30 at 21:56 user30113140user30113140 12 bronze badges New contributor user30113140 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 1- Hello, you can format code block using 3 backticks. – XouDo Commented Mar 31 at 15:20
2 Answers
Reset to default 0Try with const string in timestamp()
drawVerticalLine(targetTime) =>
line.new(
x1 = targetTime,
y1 = low,
x2 = targetTime,
y2 = high,
xloc = xloc.bar_time,
extend = extend.both,
color = color.new(#f9961e, 10),
style = line.style_solid,
width = 1)
// Lines to Plot//
targetTime = timestamp('2025-03-24 06:54 GMT+0')
drawVerticalLine(targetTime)
https://i.imgur/xcjOZua.png
I have found a solution to my original question.
How 'clean' it is I don't know but it works
Option 1 - Offset each // Lines to Plot
Original
// Lines to Plot
targetTime = timestamp(2025,03,14,06,54,00)
drawVerticalLine(targetTime)
Solution
targetTime = timestamp(2025,03,14,06,54,00)
offsetTime = targetTime - (time - time[1])
drawVerticalLine(offsetTime)
Option 2 - Offset within // Function drawVerticalLine
// Function drawVerticalLine
drawVerticalLine(targetTime) =>
line.new (
x1=targetTime - (time - time[1]) ,
y1=low,
x2=targetTime - (time - time[1]) ,
y2=high,
xloc=xloc.bar_time,
extend=extend.both,
color=color.new(#f9961e, 10),
style=line.style_solid,
width=1)
Logic
calculates the duration of 1 bar
time - time[1]
calculates the duration of 2 bars
time - time[2]
subtracts 1 bar
- (time - time[1])
adds 1 bar
+ (time - time[1])
adds 2 bars
+ (time - time[2])
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743973257a4538424.html
评论列表(0条)