# Draw a vertical line on 20 days

#### mini

##### Member
How to write a script to draw a vertical line on 20 days look back and the next 20 days from the beginning of the recent month (the first trading day of the month)? For example, the beginning of the recent month is December, how to write a script to draw a vertical line on 20 days look back and the next 20 days from this date? Thank you!

Solution
How to write a script to draw a vertical line on 20 days look back and the next 20 days from the beginning of the recent month (the first trading day of the month)? For example, the beginning of the recent month is December, how to write a script to draw a vertical line on 20 days look back and the next 20 days from this date? Thank you!

Enter the number of months lookback at input month_lookback to find the date of the first trading day of the month. The current month of February would be 0, to find January, then 1 and December as your example, then 2.

Then there are 2 lookbacks of input days_lookback, one from the month_begin and then the 'next' from the first days_lookback,

Code:
``input month_lookback    = 2...``
How to write a script to draw a vertical line on 20 days look back and the next 20 days from the beginning of the recent month (the first trading day of the month)? For example, the beginning of the recent month is December, how to write a script to draw a vertical line on 20 days look back and the next 20 days from this date? Thank you!

Enter the number of months lookback at input month_lookback to find the date of the first trading day of the month. The current month of February would be 0, to find January, then 1 and December as your example, then 2.

Then there are 2 lookbacks of input days_lookback, one from the month_begin and then the 'next' from the first days_lookback,

Code:
``````input month_lookback    = 2;
input days_lookback     = 20;
input showverticallines = yes;
input showlabels        = yes;

def bn              = BarNumber();
def count           = if GetMonth() != GetMonth()[1] then count[1] + 1 else count[1];
def month_count     = HighestAll(count) - count ;
def month_begin_bar = if month_count == month_lookback and month_count[1] == month_lookback + 1
then bn else Double.NaN;

GetMonth() + "/" + GetDayOfMonth(GetYYYYMMDD()) + "/" + GetYear(), Color.YELLOW);

def days_back_1 = HighestAll(month_begin_bar) - days_lookback;
GetMonth() + "/" + GetDayOfMonth(GetYYYYMMDD()) + "/" + GetYear(), Color.WHITE);

def days_back_2 = days_back_1 - days_lookback;
GetMonth() + "/" + GetDayOfMonth(GetYYYYMMDD()) + "/" + GetYear(), Color.YELLOW);

AsPrice(HighestAll(if bn == HighestAll(month_begin_bar) then GetYYYYMMDD() else Double.NaN)), Color.YELLOW);

days_lookback + " Days Before Date Begin: " +
AsPrice(HighestAll(if bn == days_back_1 then GetYYYYMMDD() else Double.NaN)), Color.WHITE);

days_lookback + " Days Before 1st Days Lookback: " +
AsPrice(HighestAll(if bn == days_back_2 then GetYYYYMMDD() else Double.NaN)), Color.YELLOW);

;``````

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