![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jul 2009
Posts: 132
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 | |
|
Senior Member
Join Date: Jul 2009
Posts: 132
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
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. |
|
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
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);
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 | |
|
Senior Member
Join Date: Jul 2009
Posts: 132
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
Damn, sorry. I thought I tried it and it didn't work. I must have done something wrong. sorry. |
|
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Jul 2009
Posts: 132
Thanks: 0
Thanked 0 times in 0 posts
|
anyway, I still think there's an issue when the GetBar() tries to evaluate a DateTime that's off the chart.
|
|
|
|
|
|
#7 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
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
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Jul 2009
Posts: 132
Thanks: 0
Thanked 0 times in 0 posts
|
Ok, thanks Josh, that explains it. I have seen GetBar() return 0 too. Is that the "cannot evaluate" response?
|
|
|
|
|
|
#9 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Correct. Or if the time you passed in is in the future.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Jul 2009
Posts: 132
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |