Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

submitting the some iorder

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

    submitting the some iorder

    Morning

    What would happen if I submit an iOrder then without checking its status set it to null and send it again, would both orders go in fine ?
    Last edited by GKonheiser; 04-15-2015, 03:17 AM. Reason: spelling

    #2
    Hello,

    Thank you for the question.

    This really depends on the type of order submitted, if it is still working and the strategies EntriesPerDirection setting.

    If you are asking about something similar to the following example:

    Code:
    IOrder exampleOrder = EnterLong();
    exampleOrder = null;
    exampleOrder = EnterLong();
    The initial order would be filled, the variable becomes null but does not affect the actual order. then if it was filled, the second order would just be ignored if you only have 1 entry per direction.

    If you had multiple entries per direction, the second order would fill and exampleOrder would point to the second order because it was re assigned, the first order will still exist.

    If the order instead had a signal name and was still working like a limit order, it would update the order rather than being ignored. This would entail that both of the Enter order methods have the same signal name specified.

    Setting the local variable you create to null will not change the actual order that is in NinjaTraders orders, it will just remove your local reference of the order.

    I look forward to being of further assistance.

    Comment


      #3
      Hi Jesse. Thanks for your help. I am using in managed orders. So if I use SubmitOrder. With a limit price and the set the iorder no null and resubmit the same I order with the same signal name then if the order is still working it will just change it?

      Another question is there a method for cancelling all orders even if you don't know what is working?

      Comment


        #4
        Hello,

        Thank you for the clarification.

        Un-Managed will work completely different in this situation.

        Lets look at this example instead:

        Code:
        IOrder exampleOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, 1, Close[0] + 10*TickSize, Close[0] + 5*TickSize, "", "TestSignalName");
        exampleOrder = null;
        exampleOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, 1, Close[0] + 10 * TickSize, Close[0] + 5 * TickSize, "", "TestSignalName");
        The initial submit order will submit an order
        your local IOrder variable is set to null so we loose the reference to the working order, it is still working though.
        Now the next SubmitOrder is called, and it does submit the order just as the prior request did. Now there are two working orders.

        The Rules of the Managed approach do not effect the unmanaged orders so in this case nothing would have effected the second call. The variable is pointing to the second IOrder but both will be working.

        In order to change an order, the Signal name actually does not update an order using unmanaged, instead you would use ChangeOrder()




        For closing all positions, this is actually something that is not currently supported. In general you would need to keep a list or array of IOrders the strategy has submitted and clean the list when the order is canceled or filled. You can look at this forum post I had commented on a while back on this topic.



        Specifically post # 2, the top section of code will Loop through the order collection. This is not a supported method but it is a way to accomplish this.

        I look forward to being of further assistance.

        Comment


          #5
          Thanks for that Jesse, OK , im going around in circles.

          Im trying to think of a way to implement a method for breaking up a big order into smaller clips. Obviously it would be nice to do it with just one IOrder but then I will not be able to cancel any of the orders if I need too. The other option is to create hundreds of IOrders and this is a very unclean way of dealing with this issue. Any thoughts?

          Comment


            #6
            Hello,

            This would likely be a good case for a List with a custom object.

            What you could do if you need a lot of IOrder objects but dont want to define a lot of variables would be to use a collection.

            Here is a really short, simple example of using a List in NinjaTrader. Pay close attention to the using statements at the top, you absolutely need using System.Collection.Generic; for this to be used.

            Code:
            using System.Collections.Generic;
            
            namespace NinjaTrader.Strategy
            {
                public class TestStrat : Strategy
                {
                    List<IOrder> ordersList = new List<IOrder>(); 
            
                    protected override void OnBarUpdate()
                    {
                        IOrder exampleOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, 1, Close[0] + 10*TickSize, Close[0] + 5*TickSize, "", "Test");
                        ordersList.Add(exampleOrder);
            
                        //later in the logic you can modify or get a order or loop through the list as needed:
            
                        foreach (var order in ordersList)
                        {
                            Print(order.Name + order.OrderId);
                        }
                    }
                }
            }
            This would be one way to accomplish what you are after will less code. You would still have many IOrders but you could loop through the collection and look for specific ID's order states, anything an IOrder contains.

            You can populate the list in the same way by looping, or using the existing logic in the script.

            I look forward to being of further assistance.

            Comment


              #7
              Hi Jesse ,

              Thx for that and sorry for taking so long to get back to you.

              How would i reference the orders after using this method, ie if I then have set the iorder to null would I have the same problem?

              Comment


                #8
                Hello,

                You can reference the order where needed such as OnExecution or OnOrderUpdate or anywhere in the script really, depending on what order you need you can locate it a few different ways.

                I will provide a couple of examples on how to use the List for these operations

                We will start with the prior example:
                Code:
                protected override void Initialize()
                {
                        CalculateOnBarClose = true;
                        Unmanaged = true;
                }
                		
                        List<IOrder> ordersList = new List<IOrder>();
                
                protected override void OnBarUpdate()
                {
                        if (Position.MarketPosition == MarketPosition.Flat)
                        {
                                IOrder exampleOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, 1, Close[0] + 10 * TickSize, Close[0] + 5 * TickSize, "", "TestSignal");
                                ordersList.Add(exampleOrder);
                         }
                }
                Now we can use the list in multiple ways, the first would be to loop through the available orders that were in the list:

                Code:
                protected override void OnExecution(IExecution execution)
                {
                	if (execution.Order != null && execution.Order.OrderState == OrderState.Filled) 
                        {
                                foreach (IOrder order in ordersList)
                                {
                                    if (order == execution.Order)
                                    {
                                        Print("Found order by Looping: " + order.Name);
                                        ordersList.Remove(order); // no need to set to null,
                                    }
                                    //or
                                    if (order.Name == "TestSignal")
                                    {
                                        Print("Found order by Looping: " + order.Name);
                                        ordersList.Remove(order); // no need to set to null,
                                                                  //removing the instance from the list will prevent you from finding it again
                                    }
                                }
                        }
                }
                Another method would be to use Linq http://www.dotnetperls.com/linq

                This would require the Using statement: using System.Linq;

                Code:
                protected override void OnExecution(IExecution execution)
                {
                	if (execution.Order != null && execution.Order.OrderState == OrderState.Filled) 
                        {
                                IOrder exampleOrder = ordersList.Find(tempVariable => tempVariable == execution.Order);
                                if (exampleOrder != null)
                                {
                                    Print("Found order using Linq: " + exampleOrder.Name);
                                    ordersList.Remove(exampleOrder);
                                }
                	}
                }
                In the Linq statement, the portion:

                Code:
                    IOrder exampleOrder = ordersList.Find(tempVariable => tempVariable == execution.Order);
                This is just looking in the list for a match, if one is found it assigns it to the order: exampleOrder.

                The portion:

                tempVariable => tempVariable == execution.Order

                is the actual syntax for the condition, tempVariable is the delegate or will be representing the row being searched in the list and the following statement after the => will be the comparison being done just like an if statement.

                I look forward to being of further assistance.

                Comment


                  #9
                  Thats a great help. Thx Jesse. ; )

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  633 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  364 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  105 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  567 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  568 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X