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!
The close price of specific date/bar
- 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
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):how can I get the close price of the first bar of Jan.3rd.2011?
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;
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
...
Try something like this:the close price of the first(or Number "N") bar of entire data series?
Code: Select all
vars: myNBarNumber(1), myClose(0);
if CurrentBar = myNBarNumber then begin
myClose = Close;
end;
Josh