Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy executing trades outside time parameters

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

    Strategy executing trades outside time parameters

    Hi,

    I am having a problem where a strategy is executing trades outside of the time parameters but what is strange is that for example I have a strategy that I have set the time to start trading above or equal to 072000 and I find that whilst it is not a big discrepancy it is entering trades at 071956 why would this occur? How can I prevent this?

    Please see the code below.

    Code:
    if (Position.MarketPosition == MarketPosition.Flat)
                
                    {
                    if (entryOrder == null && (ToTime(Time[0]) >= 072000 && ToTime(Time[0]) <= 165959))
                        
                        {
                               //Code here
                         }
    Appreciate your help,
    suprsnipes

    #2
    Is this a multi-time frame strategy?

    What does

    Print ( "Time=" + ToTime(Time[0]) ) ;

    show?

    There are rules and issues related to multi-time frame strategies in the help.



    Originally posted by suprsnipes View Post
    Hi,

    I am having a problem where a strategy is executing trades outside of the time parameters but what is strange is that for example I have a strategy that I have set the time to start trading above or equal to 072000 and I find that whilst it is not a big discrepancy it is entering trades at 071956 why would this occur? How can I prevent this?

    Please see the code below.

    Code:
    if (Position.MarketPosition == MarketPosition.Flat)
                
                    {
                    if (entryOrder == null && (ToTime(Time[0]) >= 072000 && ToTime(Time[0]) <= 165959))
                        
                        {
                               //Code here
                         }
    Appreciate your help,
    suprsnipes

    Comment


      #3
      Thanks for the advice, I used the suggested code as follows;

      Code:
      Print ( "Time=" + ToTime(Time[0])  ) ;
      And got the results as per then screenshot attached which is interesting as it clearly shows that the time is in fact rounding up. Is there some additional code that I can use to avoid this problem?

      Thanks,
      suprsnipes
      Attached Files

      Comment


        #4
        suprsnipes, which instrument / market and timeframe would this script be run on here?

        Comment


          #5
          Hi,

          Is there another way I can use time so that the code more accurately (to the second) prints out the time than the way NinjaTrader's Time function works as per the screenshot in my previous post?

          Regards,
          suprsnipes

          Comment


            #6
            Originally posted by suprsnipes View Post
            Hi,

            Is there another way I can use time so that the code more accurately (to the second) prints out the time than the way NinjaTrader's Time function works as per the screenshot in my previous post?

            Regards,
            suprsnipes
            Try Time[0].ToString()

            Comment


              #7
              Hi,

              Thanks for your help.

              It appears ToTime(Time[0]) is the current bar finish time and is 1min ahead so to speak (if using 1min bars)...does this sound right? I get the same output across 3 different machines so it must be. Please correct me if this is not the case??

              Does this mean I should use 072100 instead of 072000? Or perhaps change the code to ToTime(Time[1]) and use my original time of 072000. What would you suggest? How would you prevent the strategy from entering outside your defined times?

              Regards,
              suprsnipes

              Comment


                #8
                If you're using Time[0] on a 1-minute timeframe, the time returned is always going to be rounded to 1 full minute. This is because Time[0] gets the timestamp of the bar, and not the PC's current time. It sounds like you might want to use DateTime.Now instead of Time[0].

                Comment


                  #9
                  Appreciate your help, thanks.

                  Comment


                    #10
                    Originally posted by suprsnipes View Post
                    Appreciate your help, thanks.
                    There is a somewhat confusing(at first) example in NT help under multi time frame strategies.

                    It really takes some thought to dig into it.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    646 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    367 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    108 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    569 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    573 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X