Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ToTime Function... How does it work?

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

    ToTime Function... How does it work?

    I'm looking to recreate the ToTime function of NinjaTrader.Core.Indicator.IndicatorBase, the one that accepts a DateTime variable as an argument. However I can't use it from the NinjaTrader.Core the way I have my code setup. So I was wondering if anyone would be so kind as to maybe tell my how that function works or give me a good link to where I can go find that out.

    #2
    zwentz, it converts the DateTime object to an integer value. Perhaps easier than recreating the method may be working with the DateTime class directly - http://msdn.microsoft.com/en-us/libr...e_members.aspx

    Comment


      #3
      Thanks Bertrand! That worked for me:

      Code:
              public int ToTime(DateTime date)
              {
                  int time = 0;
                  time = date.Hour * 10000;
                  time += date.Minute * 100;
                  time += date.Second;
                  return time;
              }

      Comment


        #4
        Great, thanks for sharing your snippet here!

        Comment


          #5
          If you want your strategy to start trading at 7:00 pm EST on Sundays, and trade 24 hours a day until Friday afternoons and not take any new trades after 12:00 noon EST on Friday, how would that look?

          Comment


            #6
            You would have to program into your strategy to halt trading at the specified time and DayOfWeek while running with a 24hr session definition.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Is this how it would look???

              protected override void OnBarUpdate()
              {
              // If its Friday after noon...do not trade
              if(ToTime(Time[0]) >= 120000
              && if (Time[0].DayOfWeek == DayOfWeek.Friday)
              return;
              }

              Comment


                #8
                Code:
                if (ToTime(Time[0]) > 120000 && Time[0].DayOfWeek == DayOfWeek.Sunday)
                     return;
                You want 24 hrs for all days but Sunday. So you need to return on Sunday, not Friday.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks Josh!

                  Comment


                    #10
                    Actually, I do not want to trade on Fridays after noon????

                    Comment


                      #11
                      Then just change the snippet to DayOfWeek.Friday....

                      Comment


                        #12
                        OK...Thanks!

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        648 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        369 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        109 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        573 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        576 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X