Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Canceling All Orders

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

    Canceling All Orders

    My strategy at times tries to reverse its position, and when it does so it first cancels all orders and then places an order to negate my current position. It appears though that my orders are not getting canceled when I look at the execution history in my backtesting. The way I cancel all orders is to do the following:

    Code:
    for(int i = 0; i < this.Orders.Count; i++)
    {
    	this.Orders[i].Cancel();
    }
    Is there something wrong with this logic?

    #2
    Hello hamburglergt,

    We unfortunately do not support working from an orders collection. To cancel orders you must structure them as IOrder and then the IOrder object is passed into CancelOrder() method. This sample can help with CancelOrder() technique:
    When using NinjaTrader's Enter() and Exit() methods, the default behavior is to automatically expire them at the end of a bar unless they are resubmitted to keep them alive. Sometimes you may want more flexibility in this behavior and wish to submit orders as live-until-cancelled. When orders are submitted as live-until
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      So how can I retrieve all IOrder objects to cancel them?

      Comment


        #4
        You pass in the IOrder object into CancelOrder() to cancel it. There's unfortunately not support for an IOrder collection although some users report success using this. NinjaScript is an extension of C# so there is a lot of flexibility in what you can do. However, we can only provide support for the NinjaScript items in our help guide and reference sample on these forums.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          My question was a ninjascript question...how do i retrieve all orders? If you're saying the Cancel() method does not work, then how do i obtain all IOrder objects in order to call CancelOrder() on them.

          Comment


            #6
            There is not a bulit in method that can be used to retrieve all orders. You can use that sample for reference on how to use CancelOrder(), which accepts an individual IOrder object. An important concept to understand is that the strategy is only aware of orders submitted by the particular strategy instance you're using.

            If you are an advanced programmer then you may be able to build an IOrder collection to manage and use. We will not develop this for you, although you can check this sample for some ideas.

            If you are not a programmer or have limited time to develop this concept, you may consider hiring a 3rd party NinjaScript consultant to help with areas that are outside of our scope of support. A complete list is available here:
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by GussJ, 03-04-2020, 03:11 PM
            11 responses
            3,221 views
            0 likes
            Last Post xiinteractive  
            Started by andrewtrades, Today, 04:57 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            7 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            438 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            9 views
            0 likes
            Last Post FAQtrader  
            Working...
            X