Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problems with TD Ameritrade

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

    Problems with TD Ameritrade

    I have TD Ameritrade connector license and I am having issues.

    1. ATM Strategies could place orders but they cant modify them example Trail Stops or Updates to Limit Orders are failing and the Order in Ninja Trader gets cancelled while the original (Stop & Limit) orders in TD Ameritrade remain intact.

    2. Even manual updates (like changing the quantity or the price) of Stop / Limit Orders in Ninja Trader fails and cancels the original orders in Ninja Trader only without impacting the order in TD Ameritrade.

    3. Some Order events are getting missed. I see some close happened in TD Ameritrade upon the open of Market at 9:30 but Ninja Trader never received those Order Events.

    Has anyone else faced the similar issues.

    #2
    CRITICAL — If your inquiry involves live orders, please always reach out to your broker's Orders Desk immediately to confirm and manage your live orders and positions.

    What you're reporting is an expected limitation of the TD Ameritrade API and is listed as a disclaimer in the Connection Guide and would have also been presented to you as a pop up when configuring the TD Ameritrade connection in the platform:
    • When submitting orders within an OCO group, the orders must be submitted as a pair and after submission, those orders will no longer be modifiable. To make a change to an OCO grouped order it must be cancelled and resubmitted. ATM functionality which would modify submitted stops and targets on TD Ameritrade accounts are therefore not supported.
    • https://ninjatrader.com/ConnectionGu...nnection-Guide
    In your TD Ameritrade connection, is 'Local OCO simulation' enabled or disabled? To check, go to the Control Center > Connections > Configure > Select your TD Ameritrade connection from the lower left 'Configured' list > Look on the right:


    Comment


      #3
      Local OCO Simulation is Unchecked.
      Should I check it to simulate the behavior locally ?
      In other words if I do that will Ninja Trader cancel and create orders in TD Ameritrade whenever ATM Strategy triggers an update to the order , or if I modify it manually ?

      Comment


        #4
        No, unfortunately there is no way to work around this TD Ameritrade limitation.

        Comment


          #5
          Is there an Event that I can subscribe to in my AddOn when ATMStrategy kicks in OrderUpdate so I can handle it by canceling and creating the order in TDAmeritrade myself.

          Or some generic event that I can tap into before Ninja Trader attempts to make an API call to TDAmeritrade for Order Updates so I can handle it myself ?

          Comment


            #6
            Hello vivekniwas,

            You can subscribe to account OrderUpdate events, and then differentiate the orders which are owned by the ATM strategy to take your own actions.

            I have attached an indicator that subscribes to account OrderUpdate events and another experimental indicator that can help to gives some direction for tracking your ATM strategy orders. Note that this example is not complete, but serves only to provide some further direction.

            I have also attached an example for submitting orders with AddOn Framework code if you would like to programmatically submit an order with this sort of approach.

            Account.OrderUpdate - https://ninjatrader.com/support/help...rderupdate.htm

            Account.Submit (Submitting orders with AddOn code) - https://ninjatrader.com/support/help...nt8/submit.htm

            We look forward to assisting.
            Attached Files
            JimNinjaTrader Customer Service

            Comment


              #7
              So my understanding is that OrderUpdate Event is fired after the Order is updated not before that is that correct, if so how can I prevent NinjaTrader to make API call to TDAmeritrade and instead create an OIF file to cancel and create new Order.

              Just to be clear , I PLACE, UPDATE and CANCEL orders via OIF File and put the ATM Strategy Template name in that during the Order Placement.

              Will the code you sent work in this case to identify if the OrderUpdate is triggered by ATMStrategy ?
              Last edited by vivekniwas; 05-28-2020, 06:53 AM.

              Comment


                #8
                Hello vivekniwas,

                OnOrderUpdate will be called whenever an order's state changes. The OrderState of Initialized can be trapped if you want to capture that order before it submits. You could cancel it at this time with CancelOrder, but this will also leave an error message since NinjaTrader did not expect the cancellation that early.

                The ATMStrategyMonitor script I posted uses account level OrderUpdate events and checks if the order belongs to an ATM strategy. This can show you how you can identify OrderUpdates to orders that belong to an ATM strategy.

                We should note, that if you are trying to have a script cancel and replace orders, this would be much easier through the context of a NinjaScript strategy than trying to wire into an ATM strategy. For example, you can have the strategy submit a stop loss at X level, and if you want to update it to have it auto trail, cancel the order with CancelOrder, check for the cancellation in OnOrderUpdate, and then submit the new order each time you want to change it.

                The example below can be used for further direction on using OnOrderUpdate and Order objects.

                SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

                CancelOrder - https://ninjatrader.com/support/help...ancelorder.htm

                If you want to add semi automated functionality to the strategy, you can add if (State == State.Historical) return; to the strategy logic and add buttons for semi automated entries. An example strategy that adds buttons can be found below.



                The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

                We look forward to assisting.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Whats the sequence of Order Statuses.
                  I updated an outstanding Limit Order manually in Ninja Trader and got the following sequence when deployed your code to capture ATM Strategy in OnOrderUpdate

                  Change Pending
                  Accepted
                  Working

                  It also gave me an error dialog that it cant modify the order on TDAmeritrade ( like u mentioned)

                  Will it be the same sequence of statuses when update is triggered by the ATM Strategy ?

                  I am thinking of capturing Order Attributes when Status is Change Pending and compare with the ones when the status becomes Working. if they are different then Cancel and Create new. Does that sound OK.

                  Comment


                    #10
                    Hello vivekniwas,

                    Order submissions will follow Initialized, Submitted, Accepted, Working, Filled. These order updates are the same for any order submission from NinjaTrader regardless of if they are submitted from an ATM strategy, a NinjaScript strategy, or from a manual submission.

                    Printing order.ToString() in OnOrderUpdate can help to observe these states as they pass.

                    Order - https://ninjatrader.com/support/help...nt8/?order.htm

                    When testing, it is possible to cancel an order when it is in ChangePending, so you could move forward this way if you would like.

                    ​​​​​​​We look forward to assisting.
                    JimNinjaTrader Customer Service

                    Comment


                      #11
                      So here is the code snippet that I put in OnOrderUpdate

                      I am cancelling the Order and then placing the new Order with the same OcoID and same strategyID . I expect that when the ATM strategy kicks the next update, it will kick that upon the new order that I linked to the strategyID via the OIF. Let me know if this is correct.

                      I only care about the Updates by ATM Strategy / Mannual Updates from the Order Screen. New Order Placements are going fine via TDAmeritrade API unless u foresee a problem.

                      if (e.Order.Account.Strategies.Count > 0)
                      {
                      NinjaTrader.NinjaScript.AtmStrategy atmStrategy;
                      StrategyBase stratbase;
                      lock (e.Order.Account.Strategies)
                      {
                      stratbase = e.Order.Account.Strategies.FirstOrDefault(s => { lock (s.Orders) return s.Orders.FirstOrDefault(order => order == e.Order) != null; });
                      atmStrategy = stratbase as NinjaTrader.NinjaScript.AtmStrategy;
                      }
                      if (atmStrategy != null && e.OrderState.Equals(OrderState.ChangePending) && (e.Order.OrderType.Equals(OrderType.StopMarket) || e.Order.OrderType.Equals(OrderType.Limit)))
                      {
                      string account = e.Order.Account.Name;
                      string instrument = e.Order.Instrument.FullName;
                      OrderAction action = e.Order.OrderAction;
                      int quantity = e.Order.Quantity;
                      Ordertype ordertype = e.Order.OrderType;
                      double limitprice = e.Order.LimitPrice;
                      double stopprice =e.Order.StopPrice;
                      string ocoID = e.Order.Oco;
                      string strategyID = atmStrategy.Id;
                      Tradelytics.API.CreateOIF("CANCEL",account, "","","","","","","","",e.Order.Id,"","");
                      Tradelytics.API.CreateOIF("PLACE", account, instrument, action.ToString(),quantity,ordertype.ToString(),li mitprice,stopprice,"GTC",ocoID,"","",strategyID);
                      //Print(atmStrategy.Template + " " + atmStrategy.Id + " " + atmStrategy.Name + " " + e.Order.Name + " " + e.OrderState + " " + e.Order.OrderType.ToString() + " " + e.Order.OrderId);
                      }
                      }

                      Comment


                        #12
                        So it seems Cancelling one leg of OCO will cancel the other leg as well in TD Ameritrade, hence how can I create an OCO bracket via OIF and attach it to the atm strategy ? This will solve my problem.

                        Comment


                          #13
                          You have to call TDAmeritrade and have them turn off Advanced Features. I ran into a similar issue and contacted NinjaTrader support and they told me i had to do that. I called them, they turned it off and i no longer got errors or delays with orders. OCO orders won't work but stop limits and limit orders will.

                          Comment


                            #14
                            Hi authenix.. you seem to be my life saver here. Can you please tell what still wouldn't work for OCOs even after TDAmeritrade turns off Advanced Features ?

                            Comment


                              #15
                              I'm not really sure because I haven't tried an OCO in NT, only in TOS but the TSAmeritrade rep told me they wouldn't work. I just care about the order delay and limit orders for my autotrade strategies. Maybe they do work? I guess you would just need to try to place an OCO order with 1 trade to test after they turn off advanced features.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Brevo, Today, 01:45 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Brevo
                              by Brevo
                               
                              Started by aussugardefender, Today, 01:07 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post aussugardefender  
                              Started by pvincent, 06-23-2022, 12:53 PM
                              14 responses
                              240 views
                              0 likes
                              Last Post Nyman
                              by Nyman
                               
                              Started by TraderG23, 12-08-2023, 07:56 AM
                              9 responses
                              384 views
                              1 like
                              Last Post Gavini
                              by Gavini
                               
                              Started by oviejo, Today, 12:28 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post oviejo
                              by oviejo
                               
                              Working...
                              X