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

Alternative to ToTime()

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

    Alternative to ToTime()

    Is there an alternative to ToTime()?


    I'd like to use an input "TradingTime" that I can optimize to do the following:

    if(ToTime(Time[0])>=(74500 - TradingTime)&&ToTime(Time[0])<=(74500 + TradingTime))
    // Do something;
    The problem is I optimize my input from 1000 to 3000, I'll end up with something like 77500, which doesn't make any sense.

    Thnx

    #2
    Hello YakusaTrader,

    If you want to optimize a time, I generally advise to optimize the minute and hour separately as integer inputs and add these together.

    The hour would have a max size of 24 (which is then multiplied by 1000) and the minute would have a max size of 60 (which is then multiplied by 100).
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you. The problem is that I have +1000 of time and dates from past events that I'd like to backtest from. Below is a sample:

      Code:
      || ((ToDay(Time[0]) == 20180104) && (((ToTime(Time[0])) >= 120000 - TradingTime) && ((ToTime(Time[0])) <= 120000 + TradingTime)))
                      || ((ToDay(Time[0]) == 20180104) && (((ToTime(Time[0])) >= 203000 - TradingTime) && ((ToTime(Time[0])) <= 203000 + TradingTime)))
                      || ((ToDay(Time[0]) == 20180105) && (((ToTime(Time[0])) >= 60000 - TradingTime) && ((ToTime(Time[0])) <= 60000 + TradingTime)))
                      || ((ToDay(Time[0]) == 20180105) && (((ToTime(Time[0])) >= 93000 - TradingTime) && ((ToTime(Time[0])) <= 93000 + TradingTime)))
                      || ((ToDay(Time[0]) == 20180105) && (((ToTime(Time[0])) >= 93000 - TradingTime) && ((ToTime(Time[0])) <= 93000 + TradingTime)))
                      || ((ToDay(Time[0]) == 20180105) && (((ToTime(Time[0])) >= 93000 - TradingTime) && ((ToTime(Time[0])) <= 93000 + TradingTime)))
                      || ((ToDay(Time[0]) == 20180105) && (((ToTime(Time[0])) >= 93000 - TradingTime) && ((ToTime(Time[0])) <= 93000 + TradingTime)))
                      || ((ToDay(Time[0]) == 20180105) && (((ToTime(Time[0])) >= 93000 - TradingTime) && ((ToTime(Time[0])) <= 93000 + TradingTime)))
                      || ((ToDay(Time[0]) == 20180105) && (((ToTime(Time[0])) >= 93000 - TradingTime) && ((ToTime(Time[0])) <= 93000 + TradingTime)))
                      || ((ToDay(Time[0]) == 20180105) && (((ToTime(Time[0])) >= 110000 - TradingTime) && ((ToTime(Time[0])) <= 110000 + TradingTime)))
                      || ((ToDay(Time[0]) == 20180108) && (((ToTime(Time[0])) >= 113000 - TradingTime) && ((ToTime(Time[0])) <= 113000 + TradingTime)))
      Is there a work around?

      Comment


        #4
        Hello YakusaTrader,

        The number of times you use the variable doesn't matter. I still suggest the same.

        Is the TradingTime variable the input in question?

        If so, create two inputs instead, then add them together and assign this to the TradingTime variable.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          TradingTime is the input in question and I'd like to optimize it from 15 minutes to 60 minutes (FROM 15 x 1000 TO 60 x 1000)
          Since I have over thousands of fixed time past economical events that I'd like to run backtests from, I will get 209000 from 203000 (203000 + (60 x 1000)).
          209000 will not be recognized by NinjaTrader and that's the problem I am facing.
          Is there a way to convert 203000 to a different number so I can add 60 minutes to get 213000?

          Comment


            #6
            Hello YakusaTrade,

            Yes, create inputs for the minute and hour separately as integer inputs and add these together.

            The hour would have a max size of 24 (which is then multiplied by 1000) and the minute would have a max size of 60 (which is then multiplied by 100).

            Once added together assign this to the TradingTime variable (which no longer needs to be an input).
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by YakusaTrader View Post
              TradingTime is the input in question and I'd like to optimize it from 15 minutes to 60 minutes (FROM 15 x 1000 TO 60 x 1000)
              Since I have over thousands of fixed time past economical events that I'd like to run backtests from, I will get 209000 from 203000 (203000 + (60 x 1000)).
              209000 will not be recognized by NinjaTrader and that's the problem I am facing.
              Is there a way to convert 203000 to a different number so I can add 60 minutes to get 213000?
              Use the C# DateTime methods directly.

              ref: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
              https://docs.microsoft.com/en-us/dot...ystem.datetime
              Compute date and time values. Get relative dates and call DateTime constructors and properties.

              Comment


                #8
                Thank you very much koganam!

                I figured it out with:

                Code:
                (new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, Time[0].Hour, Time[0].Minute, Time[0].Second)  new DateTime(xxxx,xx,xx,x,x,x) - new TimeSpan(x,x,x)

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by cre8able, Yesterday, 07:24 PM
                1 response
                13 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by cocoescala, 10-12-2018, 11:02 PM
                6 responses
                939 views
                0 likes
                Last Post Jquiroz1975  
                Started by gbourque, Today, 06:39 AM
                1 response
                4 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by cmtjoancolmenero, Yesterday, 03:58 PM
                1 response
                17 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by benmarkal, Yesterday, 12:52 PM
                3 responses
                23 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X