How to plot Vertical lines at specific times selected in different colors

Mcanabal

Member
How to plot vertical lines at specific times selected in different colors 2 or more in one indicator
 
Last edited:
How to plot vertical lines at specific times selected in different colors 2 or more in one indicator

This will plot verticallines on intraday charts at or around the time input. As the time input may not exist on all timeframes, a workaround to show the verticalline at the bar that contains that time will plot. Sometimes this will result in 2 verticallines to surround the candle that contains the time input.

You can create more verticallines by adding inputs time3, time4, etc .... and by copying time1's verticalline set of code and change the time1 code to match your input time3, time4 etc and the color the way you want it to appear.

Screenshot-2022-10-24-075820.png
Ruby:
input time1 = 0936;
input time2 = 1001;

DefineGlobalColor("Time1", Color.WHITE);
AddVerticalLine(SecondsFromTime(time1) >= 0 and SecondsFromTime(time1)[1] <= 0, "         time1", GlobalColor("Time1"), Curve.FIRM);

DefineGlobalColor("Time2", Color.CYAN);
AddVerticalLine(SecondsFromTime(time2) >= 0 and SecondsFromTime(time2)[1] <= 0, "         time2", GlobalColor("Time2"), Curve.FIRM);
 

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

Thanks that works perfectly, however when I tried the times that I want it show some displacement from the graphic hours......example I want to mark 10:00 am and 11:00 am but hours or lines are not over the hourly candle
 
Thanks that works perfectly, however when I tried the times that I want it show some displacement from the graphic hours......example I want to mark 10:00 am and 11:00 am but hours or lines are not over the hourly candle

The verticallines code does not plot the line directly on the candle, which is what I assume your are requesting. This workaround using the undocumented and unsupported addchart() function does plot a line directly on the candle.

Screenshot-2022-10-24-085013.png
Ruby:
input time1 = 1000;
input time2 = 1100;

DefineGlobalColor("Time1", Color.WHITE);
def x1 = SecondsFromTime(time1) == 0;
def h1= if x1 then double.positiVE_INFINITY else double.nan;
def l1= if x1 then double.negative_iNFINITY else double.nan;
addchart(h1,l1,0,0,chartType.cANDLE, GlobalColor("Time1"));

DefineGlobalColor("Time2", Color.CYAN);
def x2 = SecondsFromTime(time2) == 0;
def h2= if x2 then double.positiVE_INFINITY else double.nan;
def l2= if x2 then double.negative_iNFINITY else double.nan;
addchart(h2,l2,0,0,chartType.cANDLE, GlobalColor("Time2"));
 
There is a Way that the vertical lines were paint or plotted accordingly to the color of the closing bar????? I mean if the bar closes red then vertical line is plotted red and vice-versa, meanwhile the bar still forming could be white, or just plotted the correspondent color after the bar closes either way...........your help could be very much appreciated on this.....
 
.....And in the other hand and this is not related to this topic, I just want to mention, how impress and grateful I am of be part of this community and I am amazed of the grade of knowledgment and cooperation of the participants, at this point I also want to recommends it to my trader partners and thinking to buy the VIP membership when you give some special promotion, I think its value every single $...... Very thankful guys and keep this wonderful job up!!!!!!.......
 
.....And in the other hand and this is not related to this topic, I just want to mention, how impress and grateful I am of be part of this community and I am amazed of the grade of knowledgment and cooperation of the participants, at this point I also want to recommends it to my trader partners and thinking to buy the VIP membership when you give some special promotion, I think its value every single $...... Very thankful guys and keep this wonderful job up!!!!!!.......

This seems to do a white or red or green line at the time input (note: that time needs to be on the chart you are viewing for the line to appear).

Ruby:
input time1 = 1000;
input time2 = 1100;

def c = close;
def o = open;

def x1w = SecondsFromTime(time1) == 0 and c;
def h1w= if x1w then double.positiVE_INFINITY else double.nan;
def l1w= if x1w then double.negative_iNFINITY else double.nan;
addchart(h1w,l1w,0,0,chartType.cANDLE, color.white);
def x1 = SecondsFromTime(time1) == 0 and c[-1];
def h1g= if c > o and x1 then double.positiVE_INFINITY else double.nan;
def l1g= if c > o and x1 then double.negative_iNFINITY else double.nan;
addchart(h1g,l1g,0,0,chartType.cANDLE, color.green);
def h1r= if c < o and x1 then double.positiVE_INFINITY else double.nan;
def l1r= if c < o and x1 then double.negative_iNFINITY else double.nan;
addchart(h1r,l1r,0,0,chartType.cANDLE, color.red);

def x2w = SecondsFromTime(time2) == 0 and c;
def h2w= if x2w then double.positiVE_INFINITY else double.nan;
def l2w= if x2w then double.negative_iNFINITY else double.nan;
addchart(h2w,l2w,0,0,chartType.cANDLE, color.white);
def x2 = SecondsFromTime(time2) == 0 and c[-1];
def h2g= if c > o and  x2 then double.positiVE_INFINITY else double.nan;
def l2g= if c > o and  x2 then double.negative_iNFINITY else double.nan;
addchart(h2g,l2g,0,0,chartType.cANDLE, color.green);
def h2r= if c < o and  x2 then double.positiVE_INFINITY else double.nan;
def l2r= if c < o and  x2 then double.negative_iNFINITY else double.nan;
addchart(h2r,l2r,0,0,chartType.cANDLE, color.red);
 
Apparently there is a error in the code or in the TOS, and I think that problem is related to the first bar is only 30 minutes instead an hour, for that reason the lines are displaced 1 H, I mean the 10am bar actually is 11 am and 11 h bar is 12..... do you know how to correct this?????, the way that I found to overcome this is changing the hour of the bars by -1 but this is not correct in the graphic time axis
 
Last edited:
Apparently there is a error in the code or in the TOS, and I think that problem is related to the first bar is only 30 minutes instead an hour, for that reason the lines are displaced 1 H, I mean the 10am bar actually is 11 am and 11 h bar is 12..... do you know how to correct this?????, the way that I found to overcome this is changing the hour of the bars by -1 but this is not correct in the graphic time axis

All times are ET. I have not been able to replicate what you are viewing. So provide chart information, including a screen print if you can, so it can be trouble shooted.

Here is 1330 and 1400 on a 30m chart of AAL. The 1330 bar is still open and white and nothing is plotted for the 1400 bar. I
The chart has been set to ET, even though I am in PT.

Here is the same chart and now the time is at the 1400 bar. The 1330 has changed to the color of the 1330 candle and the 1400 is white while it is developing.

Screenshot-2022-10-31-110033.png
 
Last edited:
Hi, there, there is a way to adapt this wonderful code to be used in a mobile device......that would be amazing, for my strategy use in a portable or when I travel
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
530 Online
Create Post

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.
Back
Top