PDA

View Full Version : How to get the the price of a bar by time


NinjaTrader_Ray
01-15-2007, 02:02 PM
The method "Bars.GetBar(DateTime time)" returns the bar index value representing thefirstbar (from left to right)holdingthe specified time.

For example:

int barsAgo = CurrentBar - Bars.GetBar(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 9, 0, 0, 0));
double closingPrice = Close[barsAgo];



Ray

BradB
01-24-2007, 04:20 AM
Unfortunately I don't seem to be able to back test with this method. It keeps using the current date/time, instead of the date/time of that day. Is there any other way to retrieve a closing price from a specific date/time?

NinjaTrader_Ray
01-24-2007, 04:35 AM
Then just change the parameters you pass in to reflect the bar date.

replace DateTime.Now.Year with Time[0].Year

as an example.

Ray