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 zstheorist, Today, 07:52 PM
                0 responses
                3 views
                0 likes
                Last Post zstheorist  
                Started by pmachiraju, 11-01-2023, 04:46 AM
                8 responses
                149 views
                0 likes
                Last Post rehmans
                by rehmans
                 
                Started by mattbsea, Today, 05:44 PM
                0 responses
                5 views
                0 likes
                Last Post mattbsea  
                Started by RideMe, 04-07-2024, 04:54 PM
                6 responses
                33 views
                0 likes
                Last Post RideMe
                by RideMe
                 
                Started by tkaboris, Today, 05:13 PM
                0 responses
                5 views
                0 likes
                Last Post tkaboris  
                Working...
                X