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,

Screenshot 2024-02-04 152417.png
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,

Screenshot 2024-02-04 152417.png
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;

AddVerticalLine(bn == HighestAll(month_begin_bar),
                GetMonth() + "/" + GetDayOfMonth(GetYYYYMMDD()) + "/" + GetYear(), Color.YELLOW);

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

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

AddLabel(showlabels, "Date Begin: " +
AsPrice(HighestAll(if bn == HighestAll(month_begin_bar) then GetYYYYMMDD() else Double.NaN)), Color.YELLOW);

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

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

;
 
Solution

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