# trying to get close on a specific date

#### phinds

##### New member
I searched the forum and found a couple of threads that were similar but do not solve the problem described in the first two lines here:

#test to see can I get the close on a specific previous date
# answer seems to be no, I can only get it for a specific # of days back since what goes in the bracket on close[] has to be a constant and cannot be a variable
# specifc scan shows all stocks w/ close < 105 and < 105 on a specific date NUMBER OF DAYS BACK

input BeginDate = 20220722;
def nd = DaysFromDate(BeginDate);
def x = close[5]; # I WANT THE 5 TO BE ND
plot z = if x > 100.0 and x < 105.0 then x else Double.NaN;

is there any way around this limitation?

Solution
I searched the forum and found a couple of threads that were similar but do not solve the problem described in the first two lines here:

#test to see can I get the close on a specific previous date
# answer seems to be no, I can only get it for a specific # of days back since what goes in the bracket on close[] has to be a constant and cannot be a variable
# specifc scan shows all stocks w/ close < 105 and < 105 on a specific date NUMBER OF DAYS BACK

input BeginDate = 20220722;
def nd = DaysFromDate(BeginDate);
def x = close[5]; # I WANT THE 5 TO BE ND
plot z = if x > 100.0 and x < 105.0 then x else Double.NaN;

is there any way around this limitation?

take a look at this answer...
I searched the forum and found a couple of threads that were similar but do not solve the problem described in the first two lines here:

#test to see can I get the close on a specific previous date
# answer seems to be no, I can only get it for a specific # of days back since what goes in the bracket on close[] has to be a constant and cannot be a variable
# specifc scan shows all stocks w/ close < 105 and < 105 on a specific date NUMBER OF DAYS BACK

input BeginDate = 20220722;
def nd = DaysFromDate(BeginDate);
def x = close[5]; # I WANT THE 5 TO BE ND
plot z = if x > 100.0 and x < 105.0 then x else Double.NaN;

is there any way around this limitation?

take a look at this answer
take the condition out of the verticalline and use it to determine when to read close

Code:
``````input date1 = 20220215;
def ymd = GetYYYYMMDD();
def x = ymd == date1;
def oldclose =  if barnumber() == 1 then double.nan else if x then close else oldclose[1];
#``````

Last edited:
WOZERS ! Boy you sure do know your stuff. Thanks.

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