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

Time setting.

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

    Time setting.

    Hallo. I'm tradning MHI, whih is open from 20:45 to 3:30 US time. How to set this time string to limit strategy runnig time.
    The problem is that after 24:00 time is change to 1:00
    and this code is useless:
    && ToTime(Time[0]) <= ToTime(03, 30, 0)
    && ToTime(Time[0]) >= ToTime(20, 45, 0)
    Rgds
    Czarek

    #2
    Sorry, why would code below be "useless". I suggest debugging your strategy to see when your condition triggers.

    Comment


      #3
      Maybe not useless at all but does not work properly because time [0] is greater 20:45 only untill the midnight, and is smaller atfter so strategy can't work ,same problem with first condition:
      Time[0] is smaller then 3:30 but between 20:45 and 24:00 is greater.
      This problem appear only if opening hours cross midnight.

      Comment


        #4
        I would write out some data such as Print(ToTime(Time[0])); to see what is happening...
        RayNinjaTrader Customer Service

        Comment


          #5
          I think I found solution. I use "or"
          Looks like this code works:
          && ((ToTime(Time[0]) >= ToTime(20, 45, 0) && ToTime(Time[0]) <= ToTime(24, 0, 0)) || (ToTime(Time[0]) >= ToTime( 0, 0, 0) && ToTime(Time[0]) <= ToTime(03, 30, 0)))
          I'll test it later and come back to you if problem still exist.
          Czarek

          Comment


            #6
            Hi Czarek

            here is an alternative idea:

            DateTime Start = DateTime.MaxValue
            DateTime Stop = DateTime.MinValue
            ...
            if(ToTime(Time[0]) == ToTime(20,45,0))
            {
            Start = Time[0]
            End = Start.AddMinutes(405)
            }
            ...
            if(Time[0] >= Start && Time[0] <= End)
            {
            here we go
            }

            Regards
            Ralph

            Comment


              #7
              Hi Ralph.
              Thanks a lot. Your idea is interesting. It's something new for me. I'll check them both.
              Rgds
              Czarek.

              Comment


                #8
                Hello Ralph.
                I try to use your sample in strategy but compilator show many errors. Could you explain me how to code your idea in details?
                Rgds
                Czarek

                Comment


                  #9
                  Hi Czarek,

                  Start and Stop are defined in the variable's section of your class. The code resides in OnBarUpdate().
                  What compile errors do you get?

                  Regards
                  Ralph

                  Comment


                    #10
                    HI.
                    Where to put this code:
                    DateTime Start = DateTime.MaxValue
                    DateTime Stop = DateTime.MinValue

                    Czarek

                    Comment


                      #11
                      Hi Czarek,

                      these declarations belong to the variables section of your class, ie:
                      private DateTime Start = DateTime.MaxValue;
                      Regards
                      Ralph

                      Comment


                        #12
                        Originally posted by Ralph View Post
                        Hi Czarek,

                        these declarations belong to the variables section of your class, ie:
                        private DateTime Start = DateTime.MaxValue;
                        Regards
                        Ralph
                        Hi. When I hanged End to Stop compilator accepted it.
                        Is that correct??
                        Rgds
                        Czarek.

                        Comment


                          #13
                          What is the compiler error message?

                          Comment


                            #14
                            Originally posted by Ralph View Post
                            What is the compiler error message?
                            The message is "The name End does not exist in the current context."
                            But if I change End to Stop is OK. Is this OK?
                            Czarek

                            Comment


                              #15
                              Now I understand, what you mean. I defined in my code example a variable with the name "Stop", but used a variable with the name "End". Yes, you need to change either the used name or the defined name. I didn't test the code myself.

                              Regards
                              Ralph

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ageeholdings, Today, 07:43 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post ageeholdings  
                              Started by pibrew, Today, 06:37 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post pibrew
                              by pibrew
                               
                              Started by rbeckmann05, Yesterday, 06:48 PM
                              1 response
                              14 views
                              0 likes
                              Last Post bltdavid  
                              Started by llanqui, Today, 03:53 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post llanqui
                              by llanqui
                               
                              Started by burtoninlondon, Today, 12:38 AM
                              0 responses
                              12 views
                              0 likes
                              Last Post burtoninlondon  
                              Working...
                              X