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

SleepyZ

Active member
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

Active member
@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);
 

TigerS

New member
VIP
@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);
 

Similar threads

Top