How to get the close price of specific date  [SOLVED]

Questions about MultiCharts and user contributed studies.
ctu1121
Posts: 135
Joined: 05 Jul 2012
Has thanked: 10 times
Been thanked: 4 times

How to get the close price of specific date

Postby ctu1121 » 21 Feb 2013

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

User avatar
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

Postby furytrader » 21 Feb 2013

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

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: How to get the close price of specific date  [SOLVED]

Postby evdl » 21 Feb 2013

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);

User avatar
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

Postby furytrader » 21 Feb 2013

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.

ctu1121
Posts: 135
Joined: 05 Jul 2012
Has thanked: 10 times
Been thanked: 4 times

Re: How to get the close price of specific date

Postby ctu1121 » 20 May 2013

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.



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);

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: How to get the close price of specific date

Postby evdl » 20 May 2013

No, that does not work.

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);
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.


Return to “MultiCharts”