Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Actual Time to Integer?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Actual Time to Integer?

    Hi,

    how can I convert the actual time which I assume I would get by
    xy = DateTime.Now.ToShortTimeString into an integer (like hmmss or hhmmss) to compare it with ToTime[0] integers?

    Thanks!

    #2
    Hi BillCh, you can use ToTime() to convert a .NET DateTime structure to an int value that represents time.

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Is there a function that does the opposite? Turns an integer into a DateTime?

      I'm trying to find a way to have DateTimes as User Inputs.

      Comment


        #4
        Hi Mike_D, I'm not aware of one, but you can also create an input of type DateTime for this, here's how to create user defined inputs - http://www.ninjatrader-support2.com/...ead.php?t=5782
        BertrandNinjaTrader Customer Service

        Comment


          #5
          You need to convert ints to DateTimes manually.

          Code:
          someVariable = new DateTime(yyyy, mm, dd, hh, mm, ss);
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            how to control input formatting?

            See attachment for reference. I can get user param inputs to be DateTime based and that is great. However, it shows both the Date and the Time for my params. What I'd like to have is greater control on input format - kind of like an input mask for DateTime input.

            In image attached, StrategyBase seems to do this nicely - in the Timeframe category, the From and To are Date only type inputs allowed by user. And the Session begins (local time) and Session ends (local time) are Time only type inputs allowed by user.

            Is there anyway we can achieve this type of effect for end user? I want to have something similar to the From/To and also the Session begins/ends type of inputting by the end user for different params I'm setting up.

            Thanks,

            JD
            Attached Files

            Comment


              #7
              Not sure if this is what you want, but you could for example change the 'category' name under the input region properties...
              BertrandNinjaTrader Customer Service

              Comment


                #8
                No, I know how to change Category name and have played with that before. But this isn't essence of my post. I'm after how to control the formatting of the right hand column for DateTime type params. I see that the "From", "To", "Session begins (local time)", and "Session ends (local time)" within StrategyBase C# definition are all DateTime objects. Yet they can be controlled formatting wise - one half to be date only, the other half to be Time only. That is what I'd like to do too with my own custom DateTime parameters but I'm not sure if I can achieve that effect like shown in the attachment.

                Comment


                  #9
                  Thanks for clarifying, you can achieve this with two separate inputs - one of DataTime, the other of TimeSpan - http://msdn.microsoft.com/en-us/libr...n_members.aspx
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    duration

                    Originally posted by NinjaTrader_Josh View Post
                    You need to convert ints to DateTimes manually.

                    Code:
                    someVariable = new DateTime(yyyy, mm, dd, hh, mm, ss);
                    Hi Josh,

                    I've used this method to get the duration between two DateTimes:
                    System.DateTime date1 = new System.DateTime(1996, 6, 3, 22, 15, 0);
                    System.DateTime date2 = new System.DateTime(1996, 12, 6, 13, 2, 0);
                    // diff1 gets 185 days, 14 hours, and 47 minutes.
                    System.TimeSpan diff1 = date2.Subtract(date1);

                    I've got the right solution with my setting but in this form:5.05:50:00. how can I format this value in other format? I 've used this: http://msdn.microsoft.com/en-us/library/az4se3k1.aspx, but it can't accept them.
                    I like to see it in form dd/hh/mm.
                    thanks a lot. Tom
                    Last edited by marotom; 05-16-2011, 10:22 AM.

                    Comment


                      #11
                      Hi Tom, this will not work as TimeSpan ToString conversion method offers no parameters, but I believe that might do the trick for you :

                      string test = (DateTime.MinValue + diff1).ToString("dd:hh:mm");
                      BertrandNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by f.saeidi, Yesterday, 02:09 PM
                      3 responses
                      18 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by Jltarrau, Today, 05:57 AM
                      1 response
                      5 views
                      0 likes
                      Last Post NinjaTrader_LuisH  
                      Started by kujista, Today, 06:23 AM
                      0 responses
                      2 views
                      0 likes
                      Last Post kujista
                      by kujista
                       
                      Started by traderqz, Yesterday, 04:32 PM
                      1 response
                      12 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by f.saeidi, Today, 05:56 AM
                      1 response
                      5 views
                      0 likes
                      Last Post Jltarrau  
                      Working...
                      X