PDA

View Full Version : Help code error


ATI user
12-20-2007, 06:46 PM
the following code from Help under GetBar() does not compile:


// Check that its past 9:45 AM
if (ToTime(Time[0]) >= ToTime(9, 45, 00))
{
// Calculate the bars ago value for the 9 AM bar for the current day
int barsAgo = CurrentBar - Bars.GetBar(new DateTime(2006, 12, 18, 9, 0, 0));

// Print out the 9 AM bar closing price
Print("The close price on the 9 AM bar was: " + Close[barsAgo].ToString());
}

NinjaTrader_Josh
12-20-2007, 11:49 PM
Hmm. It compiles fine for me. Could you please inform us as to the error you are receiving preventing the compile? Thanks.

NinjaTrader_Dierk
12-21-2007, 12:08 AM
Does compile for strategies but not for indicators. Fixed with next update of NT6.5. Thanks for reporting.

ATI user
12-21-2007, 02:53 AM
Thanks.

Yes...I was trying to compile it in an Indicator.

Does it return the actual time?...or the bar timestamp?

The reason I was trying to use it was that I want to do a calculation at 10:00 AM on a 5 min chart. If I check the time using Time.Hour and Time.Minute my calculation takes place at 9:55...i.e. the first tick of the 10:00 bar or 5 mins too early.

I suppose I could check for the first tick of the 10:05 bar....but thought maybe ToTime would work.

I need a LastTickOfBar...

or...maybe use the chart interval?...in efs the code would be GetInterval() to pick up the interval of the chart....what is it in ninjascript please.

NinjaTrader_Dierk
12-21-2007, 02:55 AM
http://www.ninjatrader-support.com/HelpGuideV6/ToTime.html

ATI user
12-21-2007, 03:30 AM
that does not work Dierk

per my post, I am trying to perform a calculation on the last tick of the 10:00 bar, not when NT starts building the 10:00 bar

on a 5 min chart, the 10:00 timestamp occurs at the start of the bar which is 09:55:01...not at 10:00:00...because that is how NT builds bars

I do not want to calculate at 09:55:01

NinjaTrader_Dierk
12-21-2007, 04:37 AM
Sorry I don't follow.

ATI user
12-21-2007, 05:11 AM
per NT help...
Bar Time Stamp
NinjaTrader stamps a bar with the closing time of the bar. For example, a minute bar with a time of 9:31:00 AM has data from 9:30:00 AM through 9:30:59 AM.

I want to calculate with data from the last tick of the 9:31:00 bar...i.e. the data at 9:30:59

If I use Time.Minute or ToTime to check the time of the bar to start my calculation, NT tells me it is 9:31:00 at the start of the bar..i.e. 9:30:00...this is a minute too early. Even ToTime(093100) triggers at 9:30:00 and not at 9:31:00 (because NT timestamps bars with the CLOSING time of the bar)

Bottom line: I need a function LastTickOfBar to make sure I am getting the data from exactly 9:30:59 and not from the NT timestamp time which is "...the closing time of the bar"

The best workaround I have so far is to check for the first tick of the 9:32:00 and look back at the prior tick to get the data for the last tick of the 9:31:00 bar

NinjaTrader_Dierk
12-21-2007, 05:36 AM
Unfortunately "LastTickOfBar" logic is not supported.

whitmark
12-22-2007, 04:48 AM
Unfortunately, for time bars, the only way to know for certain the bar is complete is to read the next tick to see if it has a different CLOSING time stamp. If a “LastTickOfBar” function did exist for time bars, it would have to do the same process and therefore it would be cheating by looking ahead by one tick.

Regards,

Whitmark