Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Regarding ChangeOrder (unmanaged)

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

    Regarding ChangeOrder (unmanaged)

    Hi,

    I had a question regarding ChangeOrder for unmanaged orders.

    Suppose my original order was a Stop Order, e.g.

    order = SubmitOrderUnmanaged(BarsInProgress, OrderAction.Buy, OrderType.StopMarket, qty, 0, stopLevel);


    In backtest (historic simulations), my Stop Levels are coded to be always at least above Close + TickSize for Buys, or at least below Close - TickSize for Sells. Hence, in the backtest (historic simulations), my orders never get rejected.

    However, assume during live trading, for some reason whatsoever, my order does get rejected, for instance, by the time my Stop order got accepted by the broker (or the exchange) during a fast moving market, the Stop Level ended up below the current price in the market for Buys, or above the current price in the market for Sells. Now, suppose, for live trading, I want to handle the situation, that if my order is rejected, I want my order to be converted to a market order in such situations (to keep my strategy inline with its intended behavior).

    If I write the ChangeOrder within the OnOrderUpdate() class such that both limitPrice & stopPrice are 0, such as this below:


    protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice,
    Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
    {
    if (orderState == OrderState.Rejected) ChangeOrder(order, qty, 0, 0); // both limitPrice and stopPrice are 0
    }



    (i) would it then automatically convert the order.OrderType to be OrderType.Market ?

    (ii) or, alternately, is it better to generate a new market order altogether based on the original order's quantity and OrderAction (instead of trying to do ChangeOrder) ?

    Thanks.

    #2
    I believe "Rejected" is a terminating state for an order (just like "Cancelled" or "Filled"), so I don't
    think ChangeOrder is going to work.

    Suggest you try submitting a new order after your order is Rejected.

    Comment


      #3
      Hi uday12, thank you for your post.

      ChangeOrder will not change the order type. You should submit a new Market order if an order rejection occurs.

      All the best wishes!
      Chris L.NinjaTrader Customer Service

      Comment


        #4
        Uday, I've found some issues in the past with ChangeOrder() when you try to modify an order that is already partfilled without using its original Size identifier. For example:

        1. setlong = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, qty, buyprice, 0, "", "SET LONG");
        2. ChangeOrder(setlong , setlong.Quantity, buyprice, 0);

        Comment


          #5
          Originally posted by pstrusi View Post
          Uday, I've found some issues in the past with ChangeOrder() when you try to modify an order that is already partfilled without using its original Size identifier. For example:

          1. setlong = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, qty, buyprice, 0, "", "SET LONG");
          2. ChangeOrder(setlong , setlong.Quantity, buyprice, 0);
          What's the issue you found?

          Comment


            #6
            I would be curious too. Can you share?

            I am mostly working with MIT and StopMarket orders to avoid the issue of partially filled, but I recognize that in live trading there are times in fast moving markets when orders can get filled before the Change order hits the market, or orders (MIT or StopMarket) can get rejected if the market is already below or above the last Close (depending upon the case) by the time the order hits the exchange (or broker). I am trying to implement a reconciliation check with the account positions (haven't done it yet) for this issue.

            Comment


              #7
              In NT7 unmanaged mode, I can recall only one issue when changing the quantity of a PartFilled order. If the ChangeOrder reduces the Quantity to below the Filled amount, the OrderState immediately changed to OrderState.Filled -- which makes perfect sense, because there is certainly nothing further for the PartFilled order to fill. The problem is, neither OnOrderUpdate nor OnExecution were called to indicate the state changed from PartFilled to Filled.

              This is noteworthy. Why? Because in NT7 the order reference had to be properly nullified in the correct handler. For OrderState.Cancelled, it was typically OnOrderUpdate, but Filled orders are usually nullified in OnExecution. Since neither of these methods were called, there was a risk the order reference would never get nullified -- which could cause a problem, depending upon how strict your code was about such things.

              Comment


                #8
                Originally posted by bltdavid View Post

                What's the issue you found?
                After changing the size order with a different identifier, the Algorithm, working or in simulation, seemed to be working normally but it was really hanged or crashed. I had to stop it and apply forensic analysis to that detrimental situation.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Mizzouman1, Today, 07:35 AM
                3 responses
                17 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by RubenCazorla, Today, 09:07 AM
                2 responses
                13 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by i019945nj, 12-14-2023, 06:41 AM
                7 responses
                82 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by timmbbo, 07-05-2023, 10:21 PM
                4 responses
                158 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by tkaboris, Today, 08:01 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X