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

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
    BertrandNinjaTrader Customer Service

    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!
        BertrandNinjaTrader Customer Service

        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....
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        OK...Thanks!

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Vulgoth_t_Destroyer, 05-09-2022, 04:45 PM
                        55 responses
                        5,455 views
                        0 likes
                        Last Post BartMan
                        by BartMan
                         
                        Started by DawnTreader, 05-08-2024, 05:58 PM
                        16 responses
                        52 views
                        0 likes
                        Last Post DawnTreader  
                        Started by tradingnasdaqprueba, 05-07-2024, 03:42 AM
                        15 responses
                        61 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Started by kevinenergy, Yesterday, 12:01 PM
                        8 responses
                        28 views
                        0 likes
                        Last Post kevinenergy  
                        Started by nightstalker, Today, 01:32 PM
                        1 response
                        12 views
                        0 likes
                        Last Post NinjaTrader_Zachary  
                        Working...
                        X