Hi there,
I would like to get the daily close price of specific date, for example, I would like to get
AAPL daily close price of 2013.2.1. I used to calculate how much K bar between 2013.2.1 and today, if there are n day, then I use close[n-1] to get close price. However, it takes a lot of time to calculate n.
May I know if there is a easier way to get AAPL daily close price for specific date? Thanks!
Charles
How to get the close price of specific date [SOLVED]
- furytrader
- Posts: 354
- Joined: 30 Jul 2010
- Location: Chicago, IL
- Has thanked: 155 times
- Been thanked: 217 times
Re: How to get the close price of specific date
I recall seeing a post a little while ago that included a "binary search" function to find bars. Binary search is a lot faster than a simple sequential search. I haven't used this function but it may be a good place to start ... ?
viewtopic.php?f=5&t=7749&hilit=binary+search
viewtopic.php?f=5&t=7749&hilit=binary+search
-
- Posts: 401
- Joined: 19 Jan 2011
- Location: Netherlands
- Has thanked: 85 times
- Been thanked: 125 times
Re: How to get the close price of specific date [SOLVED]
You can try this:
Code: Select all
variables: pricedate(0);
if date = 1130201 then begin // where YYYMMDD. 112 is 2012, 113 is 2013 etc.
pricedate = closed(0);
end;
print(pricedate);
- furytrader
- Posts: 354
- Joined: 30 Jul 2010
- Location: Chicago, IL
- Has thanked: 155 times
- Been thanked: 217 times
Re: How to get the close price of specific date
Evdl's solution will work if you're looking for a fixed date (and you know what it is when you program your system) but it won't work if you the date you're looking for changes somehow with each new bar.
Re: How to get the close price of specific date
Thanks for your suggestion. Now I can use the following code to get close price of specific date. May I use the same concept to get close price of "specific hour"?
For example, may I provide 113020123 and get the close price of 2013.2.1. PM11?
Thanks for your valuable suggestion.
For example, may I provide 113020123 and get the close price of 2013.2.1. PM11?
Thanks for your valuable suggestion.
You can try this:
Code: Select all
variables: pricedate(0);
if date = 1130201 then begin // where YYYMMDD. 112 is 2012, 113 is 2013 etc.
pricedate = closed(0);
end;
print(pricedate);
-
- Posts: 401
- Joined: 19 Jan 2011
- Location: Netherlands
- Has thanked: 85 times
- Been thanked: 125 times
Re: How to get the close price of specific date
No, that does not work.
You can use this:
But it also depends what timeframe you use. If you use a daily chart, this probably won't work. Date and time routines are described in the easy language guide. Take a look in the FAQ on the forum for links of this guide and other learning material.
You can use this:
Code: Select all
variables: pricedate(0);
if date = 1130201 and time = 2300 then begin // where YYYMMDD. 112 is 2012, 113 is 2013 etc.
pricedate = closed(0);
end;
print(pricedate);