Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ChangeOrder confusion

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

    ChangeOrder confusion

    I am running a strategy using the UNMANAGED approach on several different instruments. The strategy works fine as long as I use different account names. If I use the same account name the ChangeOrders seems to get confused (I think). How do I make sure a ChangeOrder goes with the correct IOrder?

    Should I some how be using something with 'stop1.Instrument.FullName' ?

    Here is what I think is the relevant part of my code:

    private IOrder stop1;
    private IOrder submitLong1 = null;
    ...
    submitLong1 = SubmitOrder(0,OrderAction.Buy, OrderType.Market, 1,0,0, "EnterL1","EnterLong1");
    ...
    OnExecution
    {
    ...
    stop1 = SubmitOrder(0, OrderAction.Sell, OrderType.Stop, execution.Order.Filled, stopValue, stopValue, "ExitL1", "LongStop1");
    }
    ...
    ChangeOrder(stop1, stop1.Quantity, 0, stopValue);

    Thanks
    Gordo

    #2
    Hi Gordo,

    I'm not sure what you mean by different account names here.

    ChangeOrder() is looking for the IOrder name for its first parameter. This is for the name of the order you want to change, which it looks like you are doing. One thing you may want to add here is a non-null check before attempting to modify the order.

    if (stop1 != null && otherModificationConditions)
    ChangeOrder(stop1, stop1.Quantity, 0, stopValue);
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ryan

      Thanks for the response.

      I have the null check and a few other checks.

      My question is how does NT know which IOrder to change. Let's say I have the exact same strategy running in 6E, CL, ES and the ZB. In this example I have open positions in all four of the futures. All strategies are using the account Sim101. If the strategy moves stop1 in 6E by using the ChangeOrder command, somehow the stop in CL is getting changed. Since both IOrders are named stop1 from the variable declaration, it gets confused and changes the wrong order.

      If on the other hand I have an accounts named Sim6E, SimCL, SimES and SimZB, the orders never get confused in NT.

      From a practical point of view I can not open a different account every time I want to trade a different instrument. And, I don't want to be limited to running my strategy on only one future at a time.

      Appreciate the help!

      Gordo

      Comment


        #4
        Strategies run independently from each other and the account. When you refer to an IOrder in the ChangeOrder(), this only applies to the stop1 order submitted by that particular strategy instance. If it's from a strategy running on a different symbol, there is no communication/ interaction between them.

        What you are describing does not seem to fit with this though, so I will run this scenario here to see what is happening. What version of NinjaTrader are you using? Check with Help > About.
        Last edited by NinjaTrader_RyanM1; 05-23-2011, 02:25 PM.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          I am up to date with NT 7.0.1000.5, but I have been having this issue since January.

          Comment


            #6
            I'm not seeing this on my side. I ran the same strategy against two instruments. I created a strategy where the condition before ChangeOrder() would be true on one instrument but not the other. I only see the order price changed for that instrument where it is expected, and not the other instrument.

            You may want to run your strategy on only one instrument at a time so you can make sure it's not just changing order according to the code you've written.

            If you're still seeing this issue, where it appears strategies are responding to other strategy instances: Can you please share a complete simplified file I can use to see this here? Share as well which instruments it should be applied to and the steps needed to see.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Ryan

              How about this. Based on your comments above, I went looking for something else that was not unique. Could the OCO be what is causing my problem? I am looking in the trace file and all the OCO's read the same: 'ExitL1', regardless of the instrument.

              When one instrument hit it's target, I noticed a string of three different instruments with: ...Cbi.Order.HandleOcoOrdersNow: cancel order...Oco='ExitL1'...

              I attached a 'draft' Word document with the appropriate areas of the trace file highlighted in red.

              Here is my current line of code:

              stop1 = SubmitOrder(0, OrderAction.Sell, OrderType.Stop, execution.Order.Filled, stopValue, stopValue, "ExitL1", "LongStop1");

              Because I am running the strategy in four different instruments, should it read:

              stop1 = SubmitOrder(0, OrderAction.Sell, OrderType.Stop, execution.Order.Filled, stopValue, stopValue, "ExitL1"+Instrument.FullName, "LongStop1");

              This makes the OCO's in the trace file unique. (I already tested this out). I am thinking this could be the answer. Your thoughts?

              Gordo
              Attached Files

              Comment


                #8
                Thanks for the reply. Yes, this is a good observation. The oco id passed in is not changed from what is specified in the code. This could lead to cancelled orders as a result of other strategies orders being filled.

                Using instrument name is one way to differentiate OCO Ids. For a more robust solution here, consider using C# Guid. You can generate an unique ID in OnStartUp(), and append this ID to your OCO field.

                This is beyond our scope of support, but can read more about it here:
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks for your help Ryan. This appears to be the solution to my issue. Onward and upward.

                  Comment


                    #10
                    Originally posted by NinjaTrader_RyanM View Post
                    For a more robust solution here, consider using C# Guid. You can generate an unique ID in OnStartUp(), and append this ID to your OCO field.

                    This is beyond our scope of support, but can read more about it here:
                    http://msdn.microsoft.com/en-us/libr...stem.guid.aspx
                    Ryan,

                    Out of curiousity, is this what GetAtmStrategyUnique() does (i.e., creation of a Guid)?

                    Comment


                      #11
                      KBJ, yes this would generate a unqiue string id as well.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      648 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
                      574 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X