Vertical Lines

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

This site has a very good search engine. After searching, here is a result that has an example for you in the code https://usethinkscript.com/threads/opening-range-breakout-indicator-for-thinkorswim.16/post-75429 . Just change the following to your requested time and label it how you want in place of "Open"

AddVerticalLine(SecondsFromTime(0930)==0,"Open",Color.Gray,Curve.SHORT_DASH);

SleepyZ

Well-known member
VIP
Lifetime
hey guys im looking for a 10:30AM vertical line indicator, wondering if anyone has one.

This site has a very good search engine. After searching, here is a result that has an example for you in the code https://usethinkscript.com/threads/opening-range-breakout-indicator-for-thinkorswim.16/post-75429 . Just change the following to your requested time and label it how you want in place of "Open"

AddVerticalLine(SecondsFromTime(0930)==0,"Open",Color.Gray,Curve.SHORT_DASH);
 
Solution

Shaco

Member
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(!period and SecondsFromTime(time)==0*60*60,"6:30",Color.LIME,Curve.SHORT_DASH);
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);
 

Shaco

Member
@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

Well-known member
VIP
Lifetime
@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.
Capture.jpg
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);
 

Shaco

Member
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.

Link this:
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:

Shaco

Member
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.

Link this:
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);
 

tatl

Member
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 . . .

thanks in advance
 

SleepyZ

Well-known member
VIP
Lifetime
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 . . .

thanks in advance

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.

[Edit: fix missing timeframe added]
Code:
#Verticallines_Time_Input_Exists_or_Next_if_Missing

input ShowTodayOnly = yes;

input Time1 = 0400;
input Time2 = 0930;

AddVerticalLine(
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);


AddVerticalLine(
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:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
218 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Top