PDA

View Full Version : Volume bar timer


maxpi
09-05-2007, 01:04 PM
I'm plotting volume bars and writing a simple indicator to show the amount of time elapsed from the prev bar to the current bar:

protectedoverridevoid OnBarUpdate()
{
if (CurrentBar < 2)
return;
int TimeVar =(ToTime(Time[0]))/100 -(ToTime(Time[1]))/100 ;
Plot0.Set(TimeVar);
}

I divided by 100 because I am not interested in resolution beyond a minute. This works fine unless the previous bar is before an hour rollover, ie bar[1]'s time =11:50 and bar[0]'s time = 12:04. I seem to get a 40 minute offset added to the plot for those bars. I could work around this if I could compare the left two digits of the ToTime values. Is there a way to truncate those values to the left 2 digits?

NinjaTrader_Josh
09-05-2007, 01:28 PM
What you could try is use TimeSpan objects instead.
TimeSpan timer = Time[0] - Time[1];
Plot0.Set((int)timer.Minutes);

maxpi
09-05-2007, 02:09 PM
Thanks Josh

That worked first crack out of the bag. Thanks much.

Max