price for a specified date


Category:
0
0

Hi Pete, just wonder how to define a price for a previous date. Thanks!

Marked as spam
Posted by (Questions: 7, Answers: 9)
Asked on July 16, 2017 6:24 am
2197 views
0
Private answer

Not close[1] :-). I want a code for a specific date saying 20170101. Thanks!

Marked as spam
Posted by (Questions: 7, Answers: 9)
Answered on July 16, 2017 6:29 am
0
Private answer

Very simple. However it’s very important to keep in mind the date you input must be a day of open trade for the instrument being plotted. For example, your date of 20170101 returns N/A because markets were closed on that date. So I had to change the date to 20170103. Here is the code. Screenshot shows how this appears on the chart.

def priceAtDate = if GetYYYYMMDD() == 20170103 then close else Double.NaN;
plot scan = priceAtDate;
scan.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on July 16, 2017 9:08 am
0
Private answer

Thank you Pete! Yes it works perfectly on the chart. But the price on the quote still shows NaN :-). I need the price of 2017-01-03 shown on the quotes so I can use it for some scans. By the way can you write it further if I want the prices for May 1 from 2007 to 2017 (every year) :-)? Many thanks!

Marked as spam
Posted by (Questions: 7, Answers: 9)
Answered on July 16, 2017 9:45 am
0
Hello Pete, I asked you this question earlier today Sunday, Feb 7, 2020, but in the wrong place on your website. I am trying to get a column in my Watchlist that is an ETFs current last price on a specific date. From: https://www.hahn-tech.com/ans/price-for-a-specified-date/ def priceAtDate = if GetYYYYMMDD() == 20200102 then close else Double.NaN; plot scan = priceAtDate; scan.SetPaintingStrategy(PaintingStrategy.ARROW_UP); As you replied I checked that the market was open on Thur Jan 2, 2020, and that the Watchlist column was set to Daily. But all that shows in the column is NAN However, if I use the code submitted by jx2012 on https://www.hahn-tech.com/ans/price-for-a-specified-date/ rec priceAtDate = if GetYYYYMMDD() == 20200102 then close else priceAtDate[1]; plot scan= if getYYYYMMDD() < 20200102 then Double.NaN else priceATDate; It seems to work, but I don’t trust that it gives the correct answer since the code seems quite different than yours. Also, I don’t think it gives the current last price. Please comment. Regards, Art
( at February 9, 2020 2:17 pm)
0
I tested the code and it does indeed work. You are correct in that it does not display the "current last price" because the whole idea is to display the close from a specified date. I'm not sure why you don't trust this. It takes all of about 45 seconds to test and confirm it is accurate. What am I missing?
( at February 9, 2020 5:19 pm)
0
Private answer

Pete, is GetYYYYMMDD()for current date? I want to get prices for old days. Something like Close("spy",GetYYYYMMDD() == 20170103) but not works :-). Please help! Thanks!

Marked as spam
Posted by (Questions: 7, Answers: 9)
Answered on July 16, 2017 10:32 am
0
Private answer

Pete, I think I got it :-). Here’s it. Could you polish it a little bit :-)? I want a script for prices changes in May in the last 5 years. Thanks a lot!

rec priceAtDate = if GetYYYYMMDD() == 20170103 then close else priceAtDate[1];
plot scan= if getYYYYMMDD() < 20170103 then Double.NaN else priceATDate;

Marked as spam
Posted by (Questions: 7, Answers: 9)
Answered on July 16, 2017 11:00 am
0

The scan will only go back 2 calendar years. You cannot get the price for years 3-5.

( at July 16, 2017 11:32 am)