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

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

    ToTime

    When using the following ToTime condition:

    if (ToTime(Time[0]) >= ToTime(13,00,00)&& ToTime(Time[0]) <= ToTime(14,30,00 ));

    For some reason is not working within the time requested. Order either gets placed before time or not placed at all. If I take out the ToTime condition then strategy works fine, but I'll like it to work in a specific Time frame.
    Am I missing something?

    Thanks,

    #2
    Try this:

    if (ToTime(Time[0]) >= 130000 && ToTime(Time[0]) <= 143000 );
    {
    // do something
    }

    Remember, the ToTime() merely converts a time in standard format to an integer. HTH.

    Whitmark
    whitmark
    NinjaTrader Ecosystem Vendor - Whitmark Development

    Comment


      #3
      Still behaves the same. Orders are getting entered before time. My Time Zone is EST.

      Comment


        #4
        You will have to add some Print() statements to debug your code. In case you have not seen it before, here is a tip that provide some guidance.

        RayNinjaTrader Customer Service

        Comment


          #5
          Hard to determine what is going on without seeing the code as the logic/syntax is good and is the same as what is posted on the help as follows:

          // Only trade between 7:45 AM and 1:45 PM
          if (ToTime(Time[0]) >= 74500 && ToTime(Time[0]) <= 134500)
          {
          // Strategy logic goes here
          }

          There must be some issue in the logic so you may want to do a Print("Before Time Check") and Print("After Time Check") above and below and monitor in the output window to ensure this if statement is getting executed. HTH

          Regards,

          Whitmark
          whitmark
          NinjaTrader Ecosystem Vendor - Whitmark Development

          Comment


            #6
            Where is it that ToTime needs to be declared? within the OnBarUpdate()?
            This is a sample of how I have it:

            protectedoverridevoid OnBarUpdate()

            {
            //Only run on real-time data
            if (Historical)
            return;
            if (ToTime(Time[0]) >= 142000 && ToTime(Time[0]) <= 173000 );

            Comment


              #7
              Yes however, your code sample for sure would cause problems since you have a semi colon after your if statement which is incorrect.

              Should be

              if (ToTime(Time[0]) >= 142000 && ToTime(Time[0]) <= 173000 )
              {
              // Do something
              }
              RayNinjaTrader Customer Service

              Comment


                #8
                Good catch Ray. My apologies, Edgar, for offering an initial solution while hastily cutting and pasting and not noticing the semicolon. No good deed goes unpunished

                I will say that this type of coding error is one hardest to detect in that it 1) syntax checks okay, 2) does not throw any runtime error and 3) executes the "then logic" in {} regardless of the conditions in the if() statement.

                Regards,

                Whitmark
                whitmark
                NinjaTrader Ecosystem Vendor - Whitmark Development

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by hazylizard, Today, 08:38 AM
                3 responses
                9 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by geddyisodin, Today, 05:20 AM
                2 responses
                18 views
                0 likes
                Last Post geddyisodin  
                Started by Max238, Today, 01:28 AM
                5 responses
                47 views
                0 likes
                Last Post Max238
                by Max238
                 
                Started by giulyko00, Yesterday, 12:03 PM
                3 responses
                13 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by habeebft, Today, 07:27 AM
                1 response
                16 views
                0 likes
                Last Post NinjaTrader_ChristopherS  
                Working...
                X