Mark 5/20/60 days from today on daily chart

This will plot a vertical line at the bar input N days from a date input. Add this indicator multiple times for each N days desired.

Code:
input n_days = 5;
input today  = 20210318;
def n_days_from_today = if GetYYYYMMDD() == today then BarNumber() + n_days else Double.NaN;
AddVerticalLine(BarNumber() == HighestAll(n_days_from_today), "                                                         " + n_days + " Days from" + " " + AsPrice(today), Color.WHITE);
 
@SleepyZ , then how to make a label instead of vertical line to indicate 5 bars prior to the current bar? Thanks!

As I am not exactly sure where you want a label to appear and what is to be displayed in the label, here are 3 methods:
Code:
input n_days = 5;
input today  = 20210318;
input showverticalline = yes;
input showbubble = yes;
input showlabel = yes;
input updown_bubblemover = 20;

def n_days_from_today = if GetYYYYMMDD() == today then BarNumber() - n_days else Double.NaN;
def priordate = if BarNumber() == HighestAll(n_days_from_today) then GetYYYYMMDD() else priordate[1];

AddVerticalLine(showverticalline and BarNumber() == HighestAll(n_days_from_today), "                                                        " + asprice(priordate) + "is" + n_days + " Days prior to " + " " + AsPrice(today), Color.WHITE);


AddChartBubble(showbubble and BarNumber() == HighestAll(n_days_from_today),
    if close>open then low - updown_bubblemover * ticksize()
    else high + updown_bubblemover * ticksize() ,
    asprice(priordate) + " is "+ n_days + " Days\n prior to " +  AsPrice(today),
    Color.WHITE,
    if close>open then no else yes);


AddLabel(showlabel, asprice(priordate) + " is " + n_days + " Days prior to " + " " + AsPrice(today) ,color.WHITE);
 
@SleepyZ @XeoNoX I've tried this way to find Nth bar prior to the last bar on the chart. And with that there is no yellow triangle alert show on the top of thinkScript Editor.

Code:
input lineLength = 5;
def lastBar_n = !IsNaN(close[-lineLength]) && IsNaN(close[-lineLength-1]);
AddVerticalLine(lastBar_n, "  " + lineLength, Color.WHITE);
 

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
590 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