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

Unmanaged: Cancel request speed

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

    Unmanaged: Cancel request speed

    Hi,

    Imagine that I have a Buy limit order in "working state", then strategy conditions ask to change that buy limit order into a buy market order, so here a little snippet to show:

    Code:
    if (  pv0>0 )
    						{
    							CancelOrder(lEntryOrder); 
    							while (lEntryOrder != null)
    							{
    								
    							}
    							lEntryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Market, (qty+Position.Quantity), 0, 0, "", "LONG");			
    						}
    As you may notice I set a While loop previous to send the new order in order to prevent any issue.
    So my doubt:
    I imagine that market, brokers, network or hardware conditions might delay or interrup a fast cancellation, so I thought that doing a previous Null check is necessary. Your Thoughts by experience ?

    Thanks in advance
    Last edited by pstrusi; 02-21-2017, 12:24 PM.

    #2
    Hi pstrusi,

    When an order is cancelled, this will trigger OnOrderUpdate() with the OrderState.Cancelled.
    I would recommend triggering the new order in OnOrderUpdate right after the state of the order changes.



    Also, when an order is cancelled, this does not cause the variable to be null. It still holds the order just with the state as cancelled.

    I would not suggest using a while loop.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post

      When an order is cancelled, this will trigger OnOrderUpdate() with the OrderState.Cancelled.
      1. Chelsea, is it not the "Cancelled" order state signal from the broker what really cancels the order, then it triggers the OnOrderUpdate() confirming it ?

      2. What happens if after I request cancelling the old limit order, without the while-loop, I submit the new market order when actually has not been received from broker the cancellation of the old limit order? would it not cause an error ?
      Last edited by pstrusi; 02-21-2017, 04:08 PM.

      Comment


        #4
        Hi pstrusi,

        When the message is received from the broker NT has to do some internal processing. When its done it updates the order object at the same time it triggers OnOrderUpdate().

        Using a while will eat up the CPU and I advise against using this unless you are making new threads and sleeping them, which I also recommend you do not do.

        Also, if you try and reuse a signal name and the order type is different, it will try and submit a new order and won't try and change the order.
        Last edited by NinjaTrader_ChelseaB; 02-21-2017, 05:16 PM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you very much for your answer Chelsea, you've cleared critical details.

          Comment


            #6
            Originally posted by NinjaTrader_ChelseaB View Post
            Also, if you try and reuse a signal name and the order type is different, it will try and submit a new order and won't try and change the order.
            Hi Chelsea,

            I have a doubt in regards to what you said ( above ):

            If I've requested a cancel for an limit entryorder , then, without to check if cancellation is done, I submit a new market entryorder ( using this very same signal name "entryorder" ) the previous limit entryorder will continue its cancellation process or will this process stop ?

            Thanks in advance

            Comment


              #7
              Hello pstrusi,

              The cancellation will likely continue, but the new order will likely be ignored due to the entries per direction and entry handling settings. The behavior will depend on these settings, but by default with a setting of 1, the old order will be cancelled, the new order using the same entry signal will be ignored if its sent before the cancellation is completed and OnOrderUpdate is triggered.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_ChelseaB View Post
                Hello pstrusi,

                The cancellation will likely continue, but the new order will likely be ignored due to the entries per direction and entry handling settings. The behavior will depend on these settings, but by default with a setting of 1, the old order will be cancelled, the new order using the same entry signal will be ignored if its sent before the cancellation is completed and OnOrderUpdate is triggered.
                Remember Chelsea we're talking about unmanaged approach, which I understand doesn't use either entries per direction and entry handling settings. However I got what you say and I'll have it in mind. Thanks a lot for the clarification.

                Best regards

                Comment


                  #9
                  Hi pstrusi,

                  Oh right. Yeah with unmanaged then new order should go through and old order should continue to cancel if CancelOrder() is called on it.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_ChelseaB View Post
                    Hi pstrusi,

                    Oh right. Yeah with unmanaged then new order should go through and old order should continue to cancel if CancelOrder() is called on it.
                    Ahhh ok, great !!

                    Thanks

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NRITV, Today, 01:15 PM
                    2 responses
                    9 views
                    0 likes
                    Last Post NRITV
                    by NRITV
                     
                    Started by frankthearm, Today, 09:08 AM
                    7 responses
                    31 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by maybeimnotrader, Yesterday, 05:46 PM
                    5 responses
                    26 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by quantismo, Yesterday, 05:13 PM
                    2 responses
                    20 views
                    0 likes
                    Last Post quantismo  
                    Started by adeelshahzad, Today, 03:54 AM
                    5 responses
                    33 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Working...
                    X