# Vertical Lines

#### ChristianDeee

##### New member
hey guys im looking for a 10:30AM vertical line indicator, wondering if anyone has one.

Solution
Hi,

I have searched but have not found an easy way to add vertical time lines or how to manipulate time (display 00:00 format) and decimal points. I want to add a vertical line and mark it at 10:45. Would want 10:45 to be an input so I can select different times when studying a chart.

When trying to convert 10:45 to 10.75 hours, I can not truncate the .75 minutes and have to resort to the round() function, which may not be correct because the 10.75 can round up to 11. A different thread suggested to try AsText(Round(time, 0)), but I get "expected double" error. My codes are below but if someone has a better function to manipulate/calculate time, please let me know. Or if there is already a similar code or better algorithm, kindly point me in the right direction.

Code:
``````declare lower;
declare hide_on_daily;

#def period = aggregationPeriod.dAY;
def startTime = 0930;
input studyTime1 = 1045;

AddVerticalLine(SecondsFromTime(startTime) == 0*60*60,  "  9:30", Color.LIME, Curve.POINTS);       #hint: 6:30 PST
AddVerticalLine(SecondsFromTime(startTime) == 0.5*60*60,  "  10", Color.LIGHT_GRAY, Curve.POINTS); #hint: 7:00 PST
AddVerticalLine(SecondsFromTime(startTime) == 1.5*60*60,  "  11", Color.LIGHT_GRAY, Curve.POINTS); #hint: 8:00 PST
AddVerticalLine(SecondsFromTime(startTime) == 2.5*60*60, "Lunch", Color.CYAN, Curve.POINTS);       #hint: 9:00 PST
AddVerticalLine(SecondsFromTime(startTime) == 3.5*60*60,   "  1", Color.LIGHT_GRAY, Curve.POINTS); #hint: 10:00 PST
AddVerticalLine(SecondsFromTime(startTime) == 4.5*60*60,   "  2", Color.LIGHT_GRAY, Curve.POINTS); #hint: 11:00 PST
AddVerticalLine(SecondsFromTime(startTime) == 5.5*60*60,   "  3", Color.LIGHT_GRAY, Curve.POINTS); #hint: 12:00 PST
AddVerticalLine(SecondsFromTime(startTime) == 6.5*60*60,   "  4", Color.ORANGE, Curve.POINTS);     #hint: 13:00 PST

# Convert military time hour to minute
def calcStartTime = (Round(startTime,-2)/100 + (startTime - Round(startTime,-2))/60)*60;
def calcStudyTime1 = (Round(studyTime1,-2)/100 + (studyTime1 - Round(studyTime1,-2))/60);

#def calcStudyMilitaryTime = AsText(Round(calcStudyTime1, 0)); #AsText(Round(price, 0))

#AddVerticalLine(SecondsFromTime(startTime) == 1*60*60,   "          " + calcStartTime + "    " + calcStudyMarineTime, Color.YELLOW, Curve.FIRM);
AddVerticalLine(SecondsFromTime(startTime) == 1.25*60*60,   "          " + calcStudyTime1, Color.YELLOW, Curve.FIRM);``````

@SleepyZ unfortunately this is not the solution i'm looking for.

I'm looking for a user input time 10:45, and the script would then auto plot a vertical line along with the label 10:45 added. I don't want to manually calculate and manually change inside my script. It would be faster to use ToS and draw a vertical line

I think the hard part about this "unrewarding" script is manipulating the math part using thinkScript, which has limited functions that I can use to truncate decimal points and only keep the ones digit (something like def time = 10.75; truncate(time, 2). Looking to get an output = 10). I'll keep looking and hope someone with an answer and kind enough to give me a hint

Last edited by a moderator:
@SleepyZ Unfortunately this is not the solution i'm looking for.

I'm looking for a user input time 10:45, and the script would then auto plot a vertical line along with the label 10:45 added. I don't want to manually calculate and manually change inside my script. It would be faster to use ToS and draw a vertical line

I think the hard part about this "unrewarding" script is manipulating the math part using thinkScript, which has limited functions that I can use to truncate decimal points and only keep the ones digit (something like def time = 10.75; truncate(time, 2). Looking to get an output = 10). I'll keep looking and hope someone with an answer and kind enough to give me a hint
This will allow you to input time as 1045 and have the label output in the vertical line be 10:45 and plot the line at that time each day.
Ruby:
``````input time  = 1045;
def hour    = Round(time / 100, 0);
def minutes = ((time / 100) - hour) * 100;
AddVerticalLine(SecondsFromTime(time) == 0, "           " + hour + ":" + minutes, Color.WHITE, stroke = Curve.FIRM);``````

Awesome @SleepyZ ! I spent 2 dayS trying to come up with this (math and logic) and you probably spent a few minutes with just 4 lines of code respect!

When I input 1055, which the codes round up and becomes round(10.55, 0) = 11:45. So i used rounddown and that fixed the issue.

Also, I'm trying a new way to do this by selecting from a pre-calculated time list instead, but i dont know how to code/link the "Time935" variable to the "AddVerticalLine(SecondsFromTime(startTime) == 300, " 9:35" , Color.YELLOW, Curve.FIRM)"; line of code.

Code:
``def Time935 = 9.583; #hint this is 9:35am``
to this:
Code:
``AddVerticalLine(SecondsFromTime(startTime) == 300, "  9:35" , Color.YELLOW, Curve.FIRM);``

Please see the updated codes below:
Code:
``````declare lower;
declare hide_on_daily;

def startTime = 0930;

# Time selection
def Time935 = 9.583; #hint this is 9:35am
def Time940 = 9.667;
def Time945 = 9.75;

input timeOptions = {default "None", "T935", "T940"};

def timeSlots = (
if timeOptions == timeOptions.T935 then Time935
else if timeOptions == timeOptions.T940 then Time940
else Time945
);

AddVerticalLine(SecondsFromTime(startTime) == 300, "  9:35" , Color.YELLOW, Curve.FIRM);
AddVerticalLine(SecondsFromTime(startTime) == 600, "  9:40" , Color.YELLOW, Curve.FIRM);
AddVerticalLine(SecondsFromTime(startTime) == 900, "  9:45" , Color.YELLOW, Curve.FIRM);

input time  = 1055;
def hour    = Round(time / 100, 0);
def minutes = ((time / 100) - hour) * 100;
AddVerticalLine(SecondsFromTime(time) == 0, "           " + hour + ":" + minutes, Color.YELLOW, stroke = Curve.FIRM);``````

Last edited:
Awesome @SleepyZ ! I spent 2 dayS trying to come up with this (math and logic) and you probably spent a few minutes with just 4 lines of code respect!

When I input 1055, which the codes round up and becomes round(10.55, 0) = 11:45. So i used rounddown and that fixed the issue.

Also, I'm trying a new way to do this by selecting from a pre-calculated time list instead, but i dont know how to code/link the "Time935" variable to the "AddVerticalLine(SecondsFromTime(startTime) == 300, " 9:35" , Color.YELLOW, Curve.FIRM)"; line of code.

Code:
``def Time935 = 9.583; #hint this is 9:35am``
to this:
Code:
``AddVerticalLine(SecondsFromTime(startTime) == 300, "  9:35" , Color.YELLOW, Curve.FIRM);``

Please see the updated codes below:
Code:
``````declare lower;
declare hide_on_daily;

def startTime = 0930;

# Time selection
def Time935 = 9.583; #hint this is 9:35am
def Time940 = 9.667;
def Time945 = 9.75;

input timeOptions = {default "None", "T935", "T940"};

def timeSlots = (
if timeOptions == timeOptions.T935 then Time935
else if timeOptions == timeOptions.T940 then Time940
else Time945
);

AddVerticalLine(SecondsFromTime(startTime) == 300, "  9:35" , Color.YELLOW, Curve.FIRM);
AddVerticalLine(SecondsFromTime(startTime) == 600, "  9:40" , Color.YELLOW, Curve.FIRM);
AddVerticalLine(SecondsFromTime(startTime) == 900, "  9:45" , Color.YELLOW, Curve.FIRM);

input time  = 1055;
def hour    = Round(time / 100, 0);
def minutes = ((time / 100) - hour) * 100;
AddVerticalLine(SecondsFromTime(time) == 0, "           " + hour + ":" + minutes, Color.YELLOW, stroke = Curve.FIRM);``````
ok, i got things to work. Here is the complete script to add vertical lines from 2 ways: user input (PST) or select from a pull down (EST). Big thanks to @SleepyZ for the inspiration!

Code:
``````declare lower;
declare hide_on_daily;

def startTime = 0930;

AddVerticalLine(SecondsFromTime(startTime) == 0,          "  9:30",     Color.LIME, Curve.POINTS); #hint: 6:30 PST
AddVerticalLine(SecondsFromTime(startTime) == 0.5*60*60,  "  10", Color.LIGHT_GRAY, Curve.POINTS); #hint: 7:00 PST
AddVerticalLine(SecondsFromTime(startTime) == 5400,       "  11", Color.LIGHT_GRAY, Curve.POINTS); #hint: 8:00 PST
AddVerticalLine(SecondsFromTime(startTime) == 9000,       "Lunch",      Color.CYAN, Curve.POINTS); #hint: 9:00 PST
AddVerticalLine(SecondsFromTime(startTime) == 12600,      "  1",  Color.LIGHT_GRAY, Curve.POINTS); #hint: 10:00 PST
AddVerticalLine(SecondsFromTime(startTime) == 16200,      "  2",  Color.LIGHT_GRAY, Curve.POINTS); #hint: 11:00 PST
AddVerticalLine(SecondsFromTime(startTime) == 19800,      "  3",  Color.LIGHT_GRAY, Curve.POINTS); #hint: 12:00 PST
AddVerticalLine(SecondsFromTime(startTime) == 6.5*60*60,  "  4",      Color.ORANGE, Curve.POINTS); #hint: 13:00 PST

# Time (EST) selection from a list
def Time0000 = 0000;
def Time0945 = 0945;
def Time1000 = 1000;
def Time1015 = 1015;
def Time1030 = 1030;
def Time1045 = 1045;
def Time1100 = 1100;
def Time1115 = 1115;
def Time1130 = 1130;
def Time1145 = 1145;
def Time1200 = 1200;
def Time1215 = 1215;
def Time1230 = 1230;
def Time1245 = 1245;
def Time1300 = 1300;

input timeOptionsEST = {default "None",
"T0945",
"T1000",
"T1015",
"T1030",
"T1045",
"T1100",
"T1115",
"T1130",
"T1145",
"T1200",
"T1215",
"T1230",
"T1245",
"T1300"
};

def timeSlots = (
if timeOptionsEST == timeOptionsEST.T0945 then Time0945
else if timeOptionsEST == timeOptionsEST.T1000 then Time1000
else if timeOptionsEST == timeOptionsEST.T1015 then Time1015
else if timeOptionsEST == timeOptionsEST.T1030 then Time1030
else if timeOptionsEST == timeOptionsEST.T1045 then Time1045
else if timeOptionsEST == timeOptionsEST.T1100 then Time1100
else if timeOptionsEST == timeOptionsEST.T1115 then Time1115
else if timeOptionsEST == timeOptionsEST.T1130 then Time1130
else if timeOptionsEST == timeOptionsEST.T1145 then Time1145
else if timeOptionsEST == timeOptionsEST.T1200 then Time1200
else if timeOptionsEST == timeOptionsEST.T1215 then Time1215
else if timeOptionsEST == timeOptionsEST.T1230 then Time1230
else if timeOptionsEST == timeOptionsEST.T1245 then Time1245
else if timeOptionsEST == timeOptionsEST.T1300 then Time1300
else Time0000
);

AddVerticalLine(SecondsFromTime(timeSlots) == 0, "", Color.YELLOW, Curve.FIRM);

# Time (PST) user input
input time  = 635;

def hour    = RoundDown(time / 100, 0);
def minute  = ((time / 100) - hour) * 100;
def hourPST = hour + 3;
def timePST = (hourPST + minute/100) * 100;

AddVerticalLine(SecondsFromTime(timePST) == 0, "", Color.YELLOW, stroke = Curve.FIRM);``````

i need a script that plots a vertical line at open . . . . and also one at the beginning of pre-market
but i need it to work on a 180d 30m chart, and ONLY plot the line for the Current day

I can only get it to plot vertical lines for every day . . .

i need a script that plots a vertical line at open . . . . and also one at the beginning of pre-market
but i need it to work on a 180d 30m chart, and ONLY plot the line for the Current day

I can only get it to plot vertical lines for every day . . .

This will plot vertical lines at the times input for the start of premarket for stocks and regular trading hours. You will need to adjust these for other non-stock symbols.

If the time does not exist on the chart, the next bar will have a vertical line.

There is an option to show the lines for only the current day.

Code:
``````#Verticallines_Time_Input_Exists_or_Next_if_Missing

input ShowTodayOnly = yes;

input Time1 = 0400;
input Time2 = 0930;

if ShowTodayOnly and GetDay() != GetLastDay()
then Double.NaN
else if SecondsFromTime(Time1) == 0
then SecondsFromTime(Time1) == 0 and SecondsTillTime(Time1) == 0
else if SecondsFromTime(Time1) != 0
then (SecondsFromTime(Time1)[1] < 0 and SecondsFromTime(Time1) > 0) or
(SecondsfromTime(Time1) > 0 and SecondsfromTime(Time1)[1] > secondsfromTime(Time1))
else  Double.NaN,
"    PreMarket Open", Color.WHITE, Curve.FIRM);

if ShowTodayOnly and GetDay() != GetLastDay()
then Double.NaN
else if SecondsFromTime(Time2) == 0
then SecondsFromTime(Time2) == 0 and SecondsTillTime(Time2) == 0
else if SecondsFromTime(Time2) != 0
then (SecondsFromTime(Time1)[1] < 0 and SecondsFromTime(Time1) > 0) or
(SecondsfromTime(Time1) > 0 and SecondsfromTime(Time1)[1] > secondsfromTime(Time1))
else  Double.NaN,
"     Market Open", Color.WHITE, Curve.FIRM);``````

Last edited:
thanks this worked great

This will plot vertical lines at the times input for the start of premarket for stocks and regular trading hours. You will need to adjust these for other non-stock symbols.

If the time does not exist on the chart, the next bar will have a vertical line.

There is an option to show the lines for only the current day.

Code:
``````#Verticallines_Time_Input_Exists_or_Next_if_Missing

input ShowTodayOnly = yes;

input Time1 = 0400;
input Time2 = 0930;

if ShowTodayOnly and GetDay() != GetLastDay()
then Double.NaN
else if SecondsFromTime(Time1) == 0
then SecondsFromTime(Time1) == 0 and SecondsTillTime(Time1) == 0
else if SecondsFromTime(Time1) != 0
then (SecondsFromTime(Time1)[1] < 0 and SecondsFromTime(Time1) > 0) or
(SecondsfromTime(Time1) > 0 and SecondsfromTime(Time1)[1] > secondsfromTime(Time1))
else  Double.NaN,
"    PreMarket Open", Color.WHITE, Curve.FIRM);

if ShowTodayOnly and GetDay() != GetLastDay()
then Double.NaN
else if SecondsFromTime(Time2) == 0
then SecondsFromTime(Time2) == 0 and SecondsTillTime(Time2) == 0
else if SecondsFromTime(Time2) != 0
then (SecondsFromTime(Time1)[1] < 0 and SecondsFromTime(Time1) > 0) or
(SecondsfromTime(Time1) > 0 and SecondsfromTime(Time1)[1] > secondsfromTime(Time1))
else  Double.NaN,
"     Market Open", Color.WHITE, Curve.FIRM);``````
Can someone help expand this code and add two times together for eg above time 1 = 0400 and I wanted to add 111 minutes to that create a new time 3. it is a formula I am trying to create so it is not easy as adding 111 min to 0400 and create a new time.. 111 min will change based on formula so if someone has code how to add time + my formula time = new time .. thanks in advance

Last edited:
Can someone help expand this code and add two times together for eg above time 1 = 0400 and I wanted to add 111 minutes to that create a new time 3. it is a formula I am trying to create so it is not easy as adding 111 min to 0400 and create a new time.. 111 min will change based on formula so if someone has code how to add time + my formula time = new time .. thanks in advance

In the example below, t2 is the new derived time from the input time1 (0930) plus the input minutes (111) equalling (1121). This should work on a 1 minute chart.
Code:
``````#Add_Minutes_to_Gettime
input time1 = 0930;
def t1 = if SecondsFromTime(time1) == 0 then GetTime() else t1[1];
def t2 = if SecondsFromTime(time1) == 0 then GetTime() + minutes_added * 60000 else t2[1];
plot t2_ = if GetTime() == t2 then 1 else Double.NaN;
t2_.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
t2_.setlineWeight(5);

input test = yes;
AddLabel(test, t1 + " " + t2, Color.YELLOW);

#``````

This will allow you to input time as 1045 and have the label output in the vertical line be 10:45 and plot the line at that time each day.
@SleepyZ

Using the same script, is it possible to create vertical lines plot for different days of the week
Eg
Mon 1045 and 1105
Tues 1100
Wed 1115 and 1130
Thur 1035
Fri 1045

Thank you

@SleepyZ

Using the same script, is it possible to create vertical lines plot for different days of the week
Eg
Mon 1045 and 1105
Tues 1100
Wed 1115 and 1130
Thur 1035
Fri 1045

Thank you

This uses the script function to allow referencing of inputs/outputs in the script without having to create multiple outputs in the study/code

Code:
``````#Mon 1045 and 1105
#Tues 1100
#Wed 1115 and 1130
#Thur 1035
#Fri 1045

script times  {
input dow   = 1;
input time1 = 1045;
def t1   = if getdayOfWeek(getyyyYMMDD()) == dow and SecondsFromTime(time1) == 0 then GetTime() else t1[1];
plot t1_ = if GetTime() == t1 then 1 else Double.NaN;
t1_.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
t1_.setlineWeight(5);

input test = no;
AddLabel(test, t1 + " " + t1, Color.YELLOW);
}

plot t_1 = times(1, 1045);
t_1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
t_1.setlineWeight(5);
plot t_2 = times(1, 1105);
t_2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
t_2.setlineWeight(5);
plot t_3 = times(2, 1100);
t_3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
t_3.setlineWeight(5);
plot t_4 = times(3, 1115);
t_4.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
t_4.setlineWeight(5);
plot t_5 = times(3, 1130);
t_5.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
t_5.setlineWeight(5);
plot t_6 = times(4, 1035);
t_6.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
t_6.setlineWeight(5);
plot t_7 = times(5, 1045);
t_7.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
t_7.setlineWeight(5);

#``````

This uses the script function to allow referencing of inputs/outputs in the script without having to create multiple outputs in the study/code
Thank you so much.
May I request to add a label on each line to differentiate the days, eg Mon, Tues Wed, Thur and Fri?

Thank you so much.
May I request to add a label on each line to differentiate the days, eg Mon, Tues Wed, Thur and Fri?

View attachment 19620

Added Days of Week and Times to Verticals

Code:
``````#Mon 1045 and 1105
#Tues 1100
#Wed 1115 and 1130
#Thur 1035
#Fri 1045

script times  {
input dow   = 1;
input time1 = 1045;
def t1   = if getdayOfWeek(getyyyYMMDD()) == dow and SecondsFromTime(time1) == 0 then GetTime() else t1[1];
plot t1_ = if GetTime() == t1 then 1 else Double.NaN;
t1_.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
t1_.setlineWeight(5);

input test = no;
AddLabel(test, t1 + " " + t1, Color.YELLOW);
}

plot t_1 = times(1, 1045);
t_1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
t_1.setlineWeight(5);
plot t_2 = times(1, 1105);
t_2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
t_2.setlineWeight(5);
plot t_3 = times(2, 1100);
t_3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
t_3.setlineWeight(5);
plot t_4 = times(3, 1115);
t_4.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
t_4.setlineWeight(5);
plot t_5 = times(3, 1130);
t_5.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
t_5.setlineWeight(5);
plot t_6 = times(4, 1035);
t_6.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
t_6.setlineWeight(5);
plot t_7 = times(5, 1045);
t_7.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
t_7.setlineWeight(5);

#``````

Is there a way to make vertical lines from a point that you set and then set an ongoing time to create vertical lines from that start point? LIke this example... lets say I want a start point at 0400 and have it make a line every 23 minutes for the rest of the day till close? The bearish example would be if I set up another script for the bearish start time say 0421 and intervals of 18 minutes... THANKS ! And one would have to change these start times and intervals every day. It's for an intraday strategy.

View attachment 20655Is there a way to make vertical lines from a point that you set and then set an ongoing time to create vertical lines from that start point? LIke this example... lets say I want a start point at 0400 and have it make a line every 23 minutes for the rest of the day till close? The bearish example would be if I set up another script for the bearish start time say 0421 and intervals of 18 minutes... THANKS ! And one would have to change these start times and intervals every day. It's for an intraday strategy.

vertical signal lines full chart Questions 3
Vertical Lines Peaks Alerts Questions 3
Vertical Lines Indicator Needed Questions 1
5 Vertical lines daily Questions 1
Vertical Time Lines Questions 9

87k+ Posts
241 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?