Is it possible to plot vertical lines on a daily chart for X days intervals?

dugafish

New member
Plus
Is it possible to plot vertical lines on a daily chart for X days intervals? For example, plot a vertical line every 20 days?
 
Last edited by a moderator:
Is it possible to plot vertical lines on a daily chart for X days intervals? For example, plot a vertical line every 20 days?

Input a start date and this should plot a vertical line starting then and every xdays (trading) days thereafter.

Capture.jpg
Ruby:
input start = 20211116;
def xdays   = 20;
def bn      = if GetYYYYMMDD() >= start then bn[1] + 1 else bn[1];

AddVerticalLine(if bn < 1 then Double.NaN else bn == 1 or !(bn % xdays), "", color = Color.YELLOW, stroke = Curve.FIRM);
 

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


Make sure that the time you enter is on the chart where you are using the code. Example, 9am start on a 1hr chart, when most start at 9:30am.

I changed the default to 5 days for testing in the following code.

Capture.jpg
Ruby:
input startdate = 20220101;
input starttime = 0930;
def xdays       = 5;
def bn          = if GetYYYYMMDD() >= startdate and SecondsFromTime(starttime) == 0
                  then 1
                  else if bn[1] >= 1
                  then bn[1] + 1
                  else bn[1];
def y           = if bn[1] == 1
                  then y[1] + 1
                  else y[1];

AddVerticalLine(  if bn < 1
                  then Double.NaN
                  else y == 0 or !(y % xdays) and SecondsFromTime(starttime) == 0,
                  "", Color.YELLOW, Curve.FIRM);
 
Last edited:
Make sure that the time you enter is on the chart where you are using the code. Example, 9am start on a 1hr chart, when most start at 9:30am.

I changed the default to 5 days for testing in the following code.
Is it possible to change this to minutes? And the start time could be set manually. I'm working on, I think, a breakthrough strategy with a friend, but it's somewhat subjective so the overall strategy can't be quantified. However, it's imperative to be able to set up vertical lines at a certain candle on the minute chart and then also set the amount of time to the next line. So some days it might be 445 am for 13 minutes... and sometimes it's 615 am for 22 minutes...

Thanks!

And if you want to know the strategy, I'll fill you guys in when I get some examples, but it's a massive pain putting in all the vertical lines.... you can manually put it in everyday, say to add the date and time .. because I'll have to do it every day, since it is an intraday only strategy.
 
Last edited by a moderator:
Is it possible to change this to minutes? And the start time could be set manually. I'm working on, I think, a breakthrough strategy with a friend, but it's somewhat subjective so the overall strategy can't be quantified. However, it's imperative to be able to set up vertical lines at a certain candle on the minute chart and then also set the amount of time to the next line. So some days it might be 445 am for 13 minutes... and sometimes it's 615 am for 22 minutes...

Thanks!

And if you want to know the strategy, I'll fill you guys in when I get some examples, but it's a massive pain putting in all the vertical lines.... you can manually put it in everyday, say to add the date and time .. because I'll have to do it every day, since it is an intraday only strategy.

This will find the time on a minute chart based upon the starttime and xminutes inputs. It will work on other chart timeframes, but will only be able to find the closest time to that on the minute chart basis.

Screenshot 2024-01-08 163206.png
Code:
#UT_Find_Time_on_Chart_xMinutes_from_Start
input starttime = 0935;
input xminutes  = 92;

input show_vertical = yes;
input show_bubble   = yes;


def bar = BarNumber();
def b   = if SecondsFromTime(starttime)[1] < 0 and SecondsFromTime(starttime) >= 0
          then bar + Round(xminutes / (GetAggregationPeriod() / 60000), 0)
          else b[1];

input timezone = {default "ET", "CT", "MT", "PT"};

def starthour  = (if timezone == timezone."ET"
                        then 9
                        else if timezone == timezone."CT"
                        then 8
                        else if timezone == timezone."MT"
                        then 7
                        else 6) ;
def hour    = Floor(((starthour * 60 + 30) + (GetTime() - RegularTradingStart(GetYYYYMMDD())) / 60000) / 60);
def minutes = (GetTime() - RegularTradingStart(GetYYYYMMDD())) / 60000 - ((hour - starthour) * 60 + 30) + 60;

AddVerticalLine(show_vertical and bar == HighestAll(b) , "                  " + if show_bubble then "" else hour + ":" + (if minutes < 10 then "0" else "" ) + minutes, Color.YELLOW, Curve.FIRM);
AddChartBubble( show_bubble and bar == HighestAll(b) , lowest(low, xminutes),
                  hour + ":" + (if minutes < 10 then "0" else "" ) + minutes, Color.YELLOW, no);
 
This will find the time on a minute chart based upon the starttime and xminutes inputs. It will work on other chart timeframes, but will only be able to find the closest time to that on the minute chart basis.
1704773971563.png

Thanks for the help. I appreciate it. This is what I got... I set it to 500 and 18 minutes... It shows 502 one line... nothing after that... I need not only it starting time, but then 18 minute intervals afterwards... so every 18 minutes after 500 it will print a line... like the red and blue ones... is that possible?
 
View attachment 20657
Thanks for the help. I appreciate it. This is what I got... I set it to 500 and 18 minutes... It shows 502 one line... nothing after that... I need not only it starting time, but then 18 minute intervals afterwards... so every 18 minutes after 500 it will print a line... like the red and blue ones... is that possible?

This will plot vertical lines starting at a date and time. Thereafter it will plot a vertical line at the minutebars input.

The minutebars is based upon bars that are actually displayed on the chart rather than a clock time. So if there is not any trading at a clock minute, then the vertical will not plot there and continue until the minutesbars are met and then plot.

The following image is /ES 1m chart. Using your start time of 0500, there is a better chance of bars for futures being trading every minute outisde rthrs and your interval may work. Otherwise this code will work best during rthrs.

Screenshot 2024-01-09 070147.png
Code:
# Vertical_Lines_Starting_at_Date/Time_and_Minutebars_Interval
# For Use on Minute Charts Only
input datebegin   = 20240109;
input timebegin   = 0500;
input minutebars  = 18;

def barStart    = if getyyyYMMDD() == datebegin and
                     SecondsfromTime(timebegin)[1] < 0 and
                     SecondsFromTime(timebegin) >= 0
                  then barnumber()
                  else double.nan;
def barcount    = if SecondsTillTime(timebegin) == 0 and
                     SecondsFromTime(timebegin) == 0
                  then 0
                  else barcount[1] + 1;

AddVerticalLine(visible = BarNumber() >= HighestAll(barstart) and (barcount) % (minutebars / (GetAggregationPeriod() / 60000)) == 0, color = Color.WHITE);
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
342 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