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

Workaround for In-Fight execution

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

    Workaround for In-Fight execution


    Hi


    I am developing strategy and using ATM to take position( AtmStrategyCreate) also AtmStrategyClose to close order.

    Despite the fact, would you please advice me how to avoid the In-Flight Executions or detect open order because of the in-fight and closed it.

    Due to this problem my account is no longer eligible for funding and I need to find solid solution for it.


    #2
    Hello bosajin,

    Below is a link to the help guide on AtmStrategy methods.


    As well as in-flight-executions.


    Is this occurring with OCO orders?
    What brokerage are you connecting to, and is this using Native or Local OCO?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi ChelseaB,

      Yes,This Is.
      I am connecting to OneUp Trader and I don't know they are using Native or Local OCO.

      Click image for larger version

Name:	image_61829.jpg
Views:	197
Size:	216.4 KB
ID:	1120087

      This is response of your support team

      The first two orders highlighted in yellow were associated with a previous order, a stop that filled and the associated target that canceled:
      • 2020-09-24 03:27:47:424|1|32|Order='1147984655/AshkanOUP09161061' Name='Stop1' New state='Filled' Instrument='YM 12-20' Action='Sell' Limit price=0 Stop price=26614 Quantity=1 Type='Stop Market' Time in force=GTC Oco='c3179bb71c874ff18c5847b1f6178106' Filled=1 Fill price=26612 Error='No error' Native error=''
      • 2020-09-24 03:27:47:424|1|32|Order='1147984656/AshkanOUP09161061' Name='Target1' New state='Cancelled' Instrument='YM 12-20' Action='Sell' Limit price=26643 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='c3179bb71c874ff18c5847b1f6178106' Filled=0 Fill price=0 Error='No error' Native error=''

      This put you in a flat position:
      • 2020-09-24 03:27:47:311|1|64|Instrument='YM 12-20' Account='AshkanOUP09161061' Average price=26637 Quantity=1 Market position=Long Operation=Remove

      Then, you entered short for four contracts with your attached strategy with a sell market order that filled at 26610.75 and 26611 (averaged out to 26611 for the entry price because there was a partial fill. This is the third highlighted entry from your screenshot:
      • 2020-09-24 03:27:47:823|1|32|Order='1147984735/AshkanOUP09161061' Name='Entry' New state='Partially filled' Instrument='YM 12-20' Action='Sell' Limit price=0 Stop price=0 Quantity=4 Type='Market' Time in force=DAY Oco='' Filled=3 Fill price=26611 Error='No error' Native error=''
      • 2020-09-24 03:27:47:948|1|32|Order='1147984735/AshkanOUP09161061' Name='Entry' New state='Filled' Instrument='YM 12-20' Action='Sell' Limit price=0 Stop price=0 Quantity=4 Type='Market' Time in force=DAY Oco='' Filled=4 Fill price=26610.75 Error='No error' Native error=''

      Your associated target filled:
      • 2020-09-24 03:28:19:414|1|32|Order='1147984737/AshkanOUP09161061' Name='Target1' New state='Filled' Instrument='YM 12-20' Action='Buy to cover' Limit price=26603 Stop price=0 Quantity=4 Type='Limit' Time in force=GTC Oco='ab2c3ef20a29418c8184dea63b550b30' Filled=4 Fill price=26603 Error='No error' Native error=''

      But then before you got a position update, you pressed 'Close':
      • 2020-09-24 03:36:33:570|1|4|Chart Trader close position

      Since you had not yet received a position update, the platform saw that you had an open position for one of those contracts and submitted a market order in the opposite direction:
      • 2020-09-24 03:36:33:977|1|32|Order='1147985412/AshkanOUP09161061' Name='Close' New state='Filled' Instrument='YM 12-20' Action='Buy to cover' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=DAY Oco='' Filled=1 Fill price=26607 Error='No error' Native error=''

      This is the fourth highlighted order in your screenshot, the close order.





      Click image for larger version

Name:	image_61830.jpg
Views:	196
Size:	169.2 KB
ID:	1120089
      ​​ Click image for larger version

Name:	image_61828.jpg
Views:	190
Size:	28.5 KB
ID:	1120090
      Attached Files

      Comment


        #4
        Also your links do not explain how to avoid the In-Fight execution.

        Comment


          #5
          Hello bosajin,

          To avoid an inflight execution you would need to know what is causing the in-flight-execution.

          This is why I have asked you for clarification before attempting to give an answer.

          As an example, lets say you are submitting a CancelOrder() without checking the state of the order first. The order has already filled and then the broker gets your cancel order request. They write back we can't this order there has been an inflight execution and the order cannot be cancelled error disables the script.

          To prevent this I would recommend checking the state of an order to still be working before calling CancelOrder(), but this may not completely prevent an in-flight-execution if an order fills after you have checked the state at the same time an cancel is being requested.

          To help lower the chances of an in-flight-execution the latency to the brokerage servers should be as low as possible. Cutting down on the communication time reduces something happening on the brokerage servers before your next communication is received. A VPS located next to the brokerage may have much lower latency, unless you personally live close to where the brokerage servers are located.


          With OCO, if it's Native OCO then it would not be OCO causing in-flight-executions as this would be handled on the brokerage end. With local OCO, NinjaTrader sends cancellation requests and this can result in an in-flight-execution. Using Native OCO could prevent OCO from causing in-flight-executions. Ensuring the latency to the brokerage servers is as low as possible can help reduce the chances of an in-flight-execution with Local OCO.


          With the message in your latest post, it looks like this was a manual close button pressed. An order was attempted to be manually cancelled but had already filled on the brokerage servers. This could indicate that the latency to the brokerage server is high, or just could have been a coincidence.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hi,

            After calling AtmStrategyClose I realized there is an open order and then I used manual close button.
            How can I recognize there is an open-order after closing ATM?
            Last edited by bosajin; 09-28-2020, 11:29 AM.

            Comment


              #7
              Hello bosajin,

              2020-09-24 03:36:33:570|1|4|Chart Trader close position

              This is from manually clicking the Close button on Chart Trader. This is does not appear when using AtmStrategyClose().

              You can see working orders on the Orders tab of the Control Center. You can see open positions on the Positions tab of the Control Center.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hi Chelsea B,

                I am trying to find another one, meanwhile would you please advice me to catch all open-positions which are made by In-Fight execution.

                Comment


                  #9
                  Hello bosajin,

                  You want to know when an order has a cancellation submitted but was filled and the order was an entry order?

                  With AtmStrategy methods you can check that the order state is CancelSubmitted but then goes back to Filled instead of Cancelled using GetAtmStrategyEntryOrderStatus().


                  Or you could use the addon approach and attach a handler to the OrderUpdate event and check that the order.OrderState is OrderState.CancelSubmitted then OrderState.Filled.

                  Chelsea B.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by aa731, Today, 02:54 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post aa731
                  by aa731
                   
                  Started by thanajo, 05-04-2021, 02:11 AM
                  3 responses
                  469 views
                  0 likes
                  Last Post tradingnasdaqprueba  
                  Started by Christopher_R, Today, 12:29 AM
                  0 responses
                  10 views
                  0 likes
                  Last Post Christopher_R  
                  Started by sidlercom80, 10-28-2023, 08:49 AM
                  166 responses
                  2,237 views
                  0 likes
                  Last Post sidlercom80  
                  Started by thread, Yesterday, 11:58 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post thread
                  by thread
                   
                  Working...
                  X