NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 08-10-2009, 09:49 AM   #1
crmcwi
Senior Member
 
Join Date: Jul 2009
Posts: 132
Thanks: 0
Thanked 0 times in 0 posts
Default Possible error with DateTime in beginning of chart?

Guys,

I think there may be a possible bug with DateTime when I try to set a DateTime object to a time before the chart begins.

My chart session begins and ends at 12:00:00 am, I'm trading FX.

My code is this:

DateTime today = new DateTime(Time[0].Ticks);
DateTime yesterday = new DateTime();
yesterday = today.AddDays(-1);
DateTime openingBell = new DateTime(yesterday.Year, yesterday.Month, yesterday.Day, 16, 0, 0);
barsAgo = GetBar(openingBell);

when backtesting, I Print("Opening Bell was at " + + Time[barsAgo].ToString() ); and I get 12:00:00, not 16:00:00 on the previous day.
crmcwi is offline  
Reply With Quote
Old 08-10-2009, 10:06 AM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

Not sure why you are doing this: DateTime today = new DateTime(Time[0].Ticks);

Time[0] is already a DateTime.

I suggest you debug what values you are actually getting for barsAgo. Then actually go back in the chart to that bar and see what the time stamp is on it.
NinjaTrader_Josh is offline  
Reply With Quote
Old 08-10-2009, 11:41 AM   #3
crmcwi
Senior Member
 
Join Date: Jul 2009
Posts: 132
Thanks: 0
Thanked 0 times in 0 posts
Default DateTime(Time[0]) won't compile

Quote:
Originally Posted by NinjaTrader_Josh View Post
Not sure why you are doing this: DateTime today = new DateTime(Time[0].Ticks);

Time[0] is already a DateTime.

I suggest you debug what values you are actually getting for barsAgo. Then actually go back in the chart to that bar and see what the time stamp is on it.

Thanks Josh, but DateTime(Time[0]) won't compile. the problem seems to be that if my session start is say, 4:00pm, the day before the chart actually begins, (I set the date range for the back test to 8/3/09, for example so at 2:00 am on 8/3/09, the session began at 4:00pm on 8/2/09) then the system gives me a start time of 12:00:00 am instead of what I explicitly set.

My CalculateOnBarUpdate = false. I think I get different behavior when it's set to true too.
crmcwi is offline  
Reply With Quote
Old 08-10-2009, 11:44 AM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

Why are you trying to go DateTime(Time[0])? It already is a DateTime containing all methods and properties of a DateTime.

DateTime someOtherDT = Time[0].AddDays(-1);
NinjaTrader_Josh is offline  
Reply With Quote
Old 08-10-2009, 12:11 PM   #5
crmcwi
Senior Member
 
Join Date: Jul 2009
Posts: 132
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
Why are you trying to go DateTime(Time[0])? It already is a DateTime containing all methods and properties of a DateTime.

DateTime someOtherDT = Time[0].AddDays(-1);

Damn, sorry. I thought I tried it and it didn't work. I must have done something wrong. sorry.
crmcwi is offline  
Reply With Quote
Old 08-10-2009, 12:12 PM   #6
crmcwi
Senior Member
 
Join Date: Jul 2009
Posts: 132
Thanks: 0
Thanked 0 times in 0 posts
Default

anyway, I still think there's an issue when the GetBar() tries to evaluate a DateTime that's off the chart.
crmcwi is offline  
Reply With Quote
Old 08-10-2009, 12:17 PM   #7
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

GetBar() evaluates the DateTime you pass into it and gets the nearest bar number related to that DateTime. Maybe this reference can be of some use: http://www.ninjatrader-support2.com/...ad.php?t=19176
NinjaTrader_Josh is offline  
Reply With Quote
Old 08-10-2009, 12:20 PM   #8
crmcwi
Senior Member
 
Join Date: Jul 2009
Posts: 132
Thanks: 0
Thanked 0 times in 0 posts
Default

Ok, thanks Josh, that explains it. I have seen GetBar() return 0 too. Is that the "cannot evaluate" response?
crmcwi is offline  
Reply With Quote
Old 08-10-2009, 12:22 PM   #9
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

Correct. Or if the time you passed in is in the future.
NinjaTrader_Josh is offline  
Reply With Quote
Old 08-10-2009, 12:32 PM   #10
crmcwi
Senior Member
 
Join Date: Jul 2009
Posts: 132
Thanks: 0
Thanked 0 times in 0 posts
Default

Cool, thank you.

I have to say, after dealing with trading technologies, CQG and that "not so easy" language, you guys are the best support team out there.
crmcwi is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
backtesting and DateTime.Now andrewbee Strategy Analyzer 3 06-28-2010 09:18 AM
DateTime Issues toptrader General Programming 4 04-28-2009 11:17 AM
enumerating each day DateTime in a chart diffused General Programming 5 02-10-2009 04:34 AM
Error - sell order on session beginning Kowal Automated Trading 15 11-28-2008 04:35 PM
DateTime as an Integer Error spinalwiz Strategy Development 2 11-18-2008 05:52 AM


All times are GMT -6. The time now is 10:22 PM.