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

Can't subtract 10 minutes from current time.

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

    Can't subtract 10 minutes from current time.

    I am trying to find the highest high and lowest low from the current time to, say, say 10 minutes ago. Why doesn't the following code give me the current hour minute an second 10 minutes ago?

    lookBackTime = 10;

    lookBackHH = Time[0].Date.AddMinutes((-1)*lookBackTime).Hour;
    lookBackMM = Time[0].Date.AddMinutes((-1)*lookBackTime).Minute;
    lookBackSS = Time[0].Date.AddMinutes((-1)*lookBackTime).Second;

    #2
    freeway, if you run this with CalculateOnBarClose = true Time[0] is the time of the last completed bar, not the currenly developing one which might be different from what you expect.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      The above coding thinks that the time is always 24:00:00 so when I subtract 10 minutes it always gives 23:50:00

      Comment


        #4
        Originally posted by freeway View Post
        I am trying to find the highest high and lowest low from the current time to, say, say 10 minutes ago. Why doesn't the following code give me the current hour minute an second 10 minutes ago?

        lookBackTime = 10;

        lookBackHH = Time[0].Date.AddMinutes((-1)*lookBackTime).Hour;
        lookBackMM = Time[0].Date.AddMinutes((-1)*lookBackTime).Minute;
        lookBackSS = Time[0].Date.AddMinutes((-1)*lookBackTime).Second;
        If you are using charts based on a minute-quantum, the barTimes are at fixed intervals, based on their closing time. Therefore, depending on your code logic, even if those variables are calculated to correct numerical values, they may not produce a meaningful result in your code.

        Comment


          #5
          I am attempting to add some code to a Strategy that is over 1000 lines long. I use Time[0] in numerous other statements to access the current candle closing time correctly. Just don't know why these statements don't work properly.

          Comment


            #6
            Have you given this already a try?

            Time[0].AddMinutes(-10);
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Originally posted by freeway View Post
              I am attempting to add some code to a Strategy that is over 1000 lines long. I use Time[0] in numerous other statements to access the current candle closing time correctly. Just don't know why these statements don't work properly.
              As stated, because of the fixed time interval between barTimes, a calculation may produce a variation where the time that you calculate falls in such a manner that a comparison does not produce the desired result. For example, on a 30-minute chart, subtracting anything less than 30 minutes will always return the current bar, as the result of your subtraction will always exceed the previous bar, as its time is fixed at 30 minutes prior to the currentBar.

              Use some Print() statements and examine the OutputWindow, and you should see what I mean. Unfortunately, code always outputs what we state, not necessarily what we intend. I have spent many a night tearing my hair out when code produced results that made no sense: until they did !

              Comment


                #8
                That gives the same result. lookBackHH = 23 lookBackMM = 50 lookBackSS = 0 for all times. It is some how thinking that the current time is 24:00:00

                I am testing this on a 1 minute chart. Trying to subtract 10 minutes from the current time.
                Last edited by freeway; 11-18-2011, 12:06 PM.

                Comment


                  #9
                  On which chart interval are you then working with it?

                  If you need access to the current PC clock time use DateTime.Now instead.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Tried DateTime.Now. It gave the same result.

                    Comment


                      #11
                      Wouldn't you want to just use Time[0].AddMinutes(), as opposed to Time[0].Date.AddMinutes() ?

                      Comment


                        #12
                        Yes, that is it. Got it to work. Thanks

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by frankthearm, Today, 09:08 AM
                        7 responses
                        29 views
                        0 likes
                        Last Post NinjaTrader_Clayton  
                        Started by NRITV, Today, 01:15 PM
                        1 response
                        5 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Started by maybeimnotrader, Yesterday, 05:46 PM
                        5 responses
                        25 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by quantismo, Yesterday, 05:13 PM
                        2 responses
                        17 views
                        0 likes
                        Last Post quantismo  
                        Started by adeelshahzad, Today, 03:54 AM
                        5 responses
                        33 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Working...
                        X