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 06-09-2007, 06:41 PM   #1
OnePutt
Junior Member
 
Join Date: Nov 2006
Location: , ,
Posts: 26
Thanks: 0
Thanked 0 times in 0 posts
Default How to add minutes to variable in ToTime format

Please provide a simple code example of how to add some number of minutes to the time when it is an integer in ToTime() format (hhmmss) . For example, what is the code to add 30 minutes (in integer format 003000) to the time 095000 (09:50:00) so that the result is 102000 (10:20:00) ? I'm not concerned about the date changing.

Question - Is there a way to convert ToTime back to DateTime() format? As before the actual date is not important - just the Time.

Thanks
OnePutt is offline  
Reply With Quote
Old 06-09-2007, 07:01 PM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

If you want to work with time at that level then I would use the DateTime structure that is returned from the Time[int barsAgo] array. ToTime() is just a method to make it easy for non-programmers to do time comparisons. Working with DateTime structures gives you complete access and flexibility.

You could do something like:

DateTime newTime = Time[0];
newTime.AddMinutes(30); // Adds 30 minutes to the value of this instance

DOC on the DateTime structure can be found here - http://msdn2.microsoft.com/en-us/lib....datetime.aspx
NinjaTrader_Ray is offline  
Reply With Quote
Old 06-09-2007, 09:08 PM   #3
OnePutt
Junior Member
 
Join Date: Nov 2006
Location: , ,
Posts: 26
Thanks: 0
Thanked 0 times in 0 posts
Default

What I need is a specific time - the day session start time (0830 Central time) in DateTime format. Then I can use AddMinutes to compute a new DateTime and finally convert back to integer time with ToTime.

How can I convert to DateTime format for today (or any day) at 0830 am such that I can add a variable number of minutes to it?
OnePutt is offline  
Reply With Quote
Old 06-09-2007, 10:53 PM   #4
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Please see the following documentation.

http://msdn2.microsoft.com/en-us/library/272ba130.aspx

This will give you an idea on how to create a specific instance of time.

For example:

DateTime newTime = new DateTime(2007, 6, 9, 8, 30, 0);
NinjaTrader_Ray is offline  
Reply With Quote
Old 06-09-2007, 11:38 PM   #5
OnePutt
Junior Member
 
Join Date: Nov 2006
Location: , ,
Posts: 26
Thanks: 0
Thanked 0 times in 0 posts
Default

I'm good to go. Thanks for the prompt reply.
OnePutt 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
Output variable values NinjaTrader_Josh Strategy Development 0 05-19-2007 09:39 PM
Exposing non dataseries variable tquinn General Programming 10 05-17-2007 04:12 PM
User variable scope ct General Programming 1 05-08-2007 07:02 AM
ToTime error The Shadow General Programming 3 03-23-2007 02:00 AM
New ToTime BradB General Programming 2 02-12-2007 04:25 AM


All times are GMT -6. The time now is 03:44 PM.