The close price of specific date/bar

Questions about MultiCharts and user contributed studies.
bucks
Posts: 5
Joined: 20 Sep 2005
Has thanked: 8 times
Been thanked: 1 time

The close price of specific date/bar

Postby bucks » 22 Jul 2011

Hi
I'm trying to find out if there's a syntax which can return the close price of a specific date(or bar).
By inserting a study of a custom line in a chart, instead of a custom indicator,
we can get the result very quickly.
Say, close[100] returns the close price of 100 bars ago;
however, for example, how can I get the close price of the first bar of Jan.3rd.2011?
or the close price of the first(or Number "N") bar of entire data series?

close[n] is moving with every new bar generated,
but close of specific previous bar(date) is fixed

thanks!

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: The close price of specific date/bar

Postby JoshM » 22 Jul 2011

how can I get the close price of the first bar of Jan.3rd.2011?
That can be done on different ways, depending on how you want to implement is. Following is one example (I've included the Print() statements to show what happens in the code, but you don't need these for the solution):

Code: Select all

vars: myYear(11), myMonth(05), myDay(16), myClose(0);

// Encode date to DateTime
value1 = EncodeDate(myYear, myMonth, myDay);

Print("Looking for date: ", FormatDate("M-d-yy", value1));

// Convert to Julian, so date of chart can be compared with entered date
value2 = JulianToDate(value1);

Print("Date of chart: ", Date, " entered Date: ", value2);

// Compare current date with entered date, and date this bar needs to be greater than date previous bar (i.e. first bar of session)
if Date = value2 and Date > Date[1] then begin
Print("Date matches and is first of that day's session");
Print("Date: ", date, " time: ", time_s);
myClose = Close;
end;
Which gives the following output:

Code: Select all

...
Looking for date: 5-16-11
Date of chart: 1110516.00 entered Date: 1110516.00
Date matches and is first of that day's session
Date: 1110516.00 time: 80151.00
...
the close price of the first(or Number "N") bar of entire data series?
Try something like this:

Code: Select all

vars: myNBarNumber(1), myClose(0);

if CurrentBar = myNBarNumber then begin
myClose = Close;
end;
Regards,
Josh


Return to “MultiCharts”