Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to cancel order within a specific time?

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

    How to cancel order within a specific time?

    Hi Support desk,
    I am running a MTF strategy and I need my order to be cancelled 1 minute before the end of the primary time frame period, I was thinking to use this code, but I was wondering if you have any better suggestions:

    Code:
    primarytimeFrame == 60 min
    secondaryTimeFrame == 1 min
    
    if(BarsInProgress == 1)
    {	
    	if (longCondition == true)
    		{
    			entryOrderLong = EnterLongLimit(1, true, 1, Low[0],"Long");
    		}
    
    //Cancel long order if not done within 1 minute to the end of primary time frame			
    if(Times[1][0] >= Times[0][0].AddMinutes(primaryTimeFrame-1) && entryOrderLong != null))
    {
    	CancelOrder(entryOrderLong);
    }
    }
    Last edited by yades; 08-13-2013, 02:00 PM.

    #2
    Hello yades,

    Thank you for your post.

    This code would not work as the Times[0][0] would never be the time you are expecting here. This means with CalculateOnBarClose = false the Times[0][0] would be the time of the most recent bar update and CalculateOnBarClose = true would be the the previous bar close.

    I recommend using CalculateOnBarClose = true and the following code in place of your time check and cancel of the order:
    Code:
    if(Times[1][0] == Times[0][0].AddMinutes(59) && entryOrderLong != null)
    {
    	CancelOrder(entryOrderLong);
    }
    Please let me know if I may be of further assistance.
    Last edited by NinjaTrader_PatrickH; 08-14-2013, 07:50 AM. Reason: Typo

    Comment


      #3
      the script below doesn't seem to compile

      Originally posted by NinjaTrader_PatrickH View Post
      Hello yades,

      Thank you for your post.

      This code would not work as the Times[0][0] would never be the time you are expecting here. This means with CalculateOnBarClose = false the Times[0][0] would be the time of the most recent bar update and CalculateOnBarClose = true would be the the previous bar close.

      I recommend using CalculateOnBarClose = true and the following code in place of your time check and cancel of the order:
      Code:
      if(ToTime(Times[1][0] == Times[0][0].AddMinutes(59) && entryOrderLong != null))
      {
      	CancelOrder(entryOrderLong);
      }
      Please let me know if I may be of further assistance.
      Last edited by sburtt; 08-13-2013, 04:00 PM.

      Comment


        #4
        Hello sburtt,

        Thank you for your response.

        Can you provide the compile error message? The code is running on my end without any errors on compile.

        Comment


          #5
          Patrick i too are unable to compile
          Last edited by yades; 08-13-2013, 11:57 PM.

          Comment


            #6
            Patrick
            do you have anything to suggest to overcome this error?

            Originally posted by NinjaTrader_PatrickH View Post
            Hello yades,

            Thank you for your post.

            This code would not work as the Times[0][0] would never be the time you are expecting here. This means with CalculateOnBarClose = false the Times[0][0] would be the time of the most recent bar update and CalculateOnBarClose = true would be the the previous bar close.

            I recommend using CalculateOnBarClose = true and the following code in place of your time check and cancel of the order:
            Code:
            if(ToTime(Times[1][0] == Times[0][0].AddMinutes(59) && entryOrderLong != null))
            {
            	CancelOrder(entryOrderLong);
            }
            Please let me know if I may be of further assistance.
            Attached Files

            Comment


              #7
              Hello yades,

              Thank you for your response.

              Please respond with the exact code you are using from your strategy that generates these error messages.

              Comment


                #8
                Patrick, that would be:

                Code:
                if(ToTime(Times[1][0] == Times[0][0].AddMinutes(59)) && entryOrderLong != null)
                {
                CancelOrder(entryOrderLong);
                }
                I was running another cancel condition within the strategy, what I did is simply substitute my prior condition with ToTime(Times[1][0] == Times[0][0].AddMinutes(59)) but I am unable to compile. I noticed that if I use something like ToTime(Times[1][0]) >= 74500 it compiles fine, to me it looks like the Times[0][0].AddMinutes(59)) doesn't return an integer value, or something similar. I tried adding (int) infront of it, but still doesn't work

                Originally posted by NinjaTrader_PatrickH View Post
                Hello yades,

                Thank you for your response.

                Please respond with the exact code you are using from your strategy that generates these error messages.

                Comment


                  #9
                  Hello yades,

                  Thank you for your response.

                  This is due to a typo in post #2 from me, it should actually be the following:
                  Code:
                  if(Times[0][0] == Times[1][0].AddMinutes(59) && entryOrderLong != null)
                  ToTime() is not used, I have corrected my post.

                  Thank you for pointing this out, much appreciated.

                  Comment


                    #10
                    Patrick

                    allow me to disagree, if you carefully read my initial remarks you will come to the conclusion that the code I had initially proposed is the correct one, then I can use a >= or ==, at least in back testing it doesn't make a difference. but what you quote below doesn't help me as my primary timeframe (60 min) is set to BarsArray[0]

                    Originally posted by NinjaTrader_PatrickH View Post
                    Hello yades,

                    Thank you for your response.

                    This is due to a typo in post #2 from me, it should actually be the following:
                    Code:
                    if(Times[0][0] == Times[1][0].AddMinutes(59) && entryOrderLong != null)
                    ToTime() is not used, I have corrected my post.

                    Thank you for pointing this out, much appreciated.

                    Comment


                      #11
                      Originally posted by NinjaTrader_PatrickH View Post
                      Hello yades,

                      Thank you for your response.

                      This is due to a typo in post #2 from me, it should actually be the following:
                      Code:
                      if(Times[0][0] == Times[1][0].AddMinutes(59) && entryOrderLong != null)
                      ToTime() is not used, I have corrected my post.

                      Thank you for pointing this out, much appreciated.
                      going through the tread I see you've amended your first reply, hence I assume your last post was a typo error

                      Comment


                        #12
                        Hello yades,

                        Thank you for your clarification.

                        Is the code working now?

                        Comment


                          #13
                          Apparently yes,
                          I will run it live and revert in case it doesnt do what i expect it to do, thanks

                          Originally posted by NinjaTrader_PatrickH View Post
                          Hello yades,

                          Thank you for your clarification.

                          Is the code working now?

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          647 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          369 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
                          572 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