Announcement

Collapse
No announcement yet.

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

              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 NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                62 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                134 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                75 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                45 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                50 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X