Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using NT8 scrip to change an order in TDAmeritrade

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

    Using NT8 scrip to change an order in TDAmeritrade

    Hi, Support Folks,

    When I was connecting to TDAmeritrade, it prompted a note saying changing an order is not supported for TDAmeritrade. Then I have a few questions here:
    1) Is this true?
    2) If yes, I would have to let my scripts cancel the existing order and re-submit a new one when conditions change; How does this affect the performance, delay within 1 second, or a few seconds comparing to a typical changing an order?
    3) Is changing order limitation only applicable to TDAmeritrade?

    Thanks.

    #2
    Hello localappleseed,

    Thank you for your posts.

    When creating strategies for use with TD Ameritrade, there are some important limitations to keep in mind.

    TD Ameritrade connections are particularly strict with NinjaScript strategies, especially with Native OCO enabled on the connection. TDA is also strict on the order in which they receive orders of different Order Actions. I.E. receiving a Buy before a Buy To Cover is received will result in a rejection.

    Once an OCO pair is submitted, it must be cancelled and replaced and TD Ameritrade will not allow modifying the orders. Set method orders cannot be canceled with CancelOrder(). Exit methods will not use OCO and can work around this limitation. (ExitLong(), for example).

    If a position is protected with working orders and NinjaTrader submits another order to exit the position, we can receive an Overbought/Oversold error.

    2020-06-03 13:50:59:743|1|32|Order='1132281582/AccountName' Name='Profit target' New state='Working' Instrument='IBM' Action='Buy to cover' Limit price=128.57 Stop price=0 Quantity=51 Type='Limit' Time in force=DAY Oco='1132281579:1371573263' Filled=0 Fill price=0 Error='No error' Native error=''

    2020-06-03 13:52:06:957|1|32|Order='4b0936b609014ef98df583e2e a3bce10/AccountName' Name='Buy to cover' New state='Rejected' Instrument='IBM' Action='Buy to cover' Limit price=0 Stop price=0 Quantity=51 Type='Market' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='Order rejected' Native error='This order may result in an oversold/overbought position in your account. Please check your position quantity and/or open orders.'

    Reversing orders may not work since NinjaTrader is multi threaded and it is possible for a Buy for a reversal to be submitted before the Buy To Cover order when reversing from a short position.

    There is also an on going issue where TDA has a delay on sending the Execution of an order after it fills.

    The above limitations are all specific to TD Ameritrade. You would need to cancel and resubmit any orders you need to change, and this would have a minor effect on performance, but I do not have a measurement of how much it would affect the performance compared to changing an order. It would likely be fairly negligible.

    Please let us know if we may be of further assistance to you.


    Comment


      #3
      What are good alternatives to TD Ameritrade?
      Something that doesn't charge me to buy and sell contracts. (NASDAQ, S&P)
      I live in the US.

      I too noticed that using them for a broker with Ninja is all sorts of problems.

      Comment


        #4
        Hello vixtor,

        Thank you for your reply.

        While I cannot give any recommendations as to your choice of broker, you can see our supported providers here:

        https://ninjatrader.com/support/help...y_provider.htm

        Please let us know if we may be of further assistance to you.

        Comment


          #5
          In your earlier replies about "especially with Native OCO enabled on the connection".
          If without OCO enabled, or if I just submit a single EnterLongLimit() order through TDA, can I use ChangeOrder()?

          Comment


            #6
            Hello localappleseed,

            Thank you for your reply.

            Local OCO does not work with TD Ameritrade; when this option is enabled in the options for the TD Ameritrade connection and you try to submit an ATM strategy (or manual OCO), TDA is not aware of any link between the orders.

            Because TDA has internal order handling rules to prevent oversold/overbought positions with unlinked orders, an error message will be received on trying to submit the second order:

            "This order may result in an oversold/overbought position in your account".

            Single, non-OCO linked orders, such as a single EnterLongLimit() entry order, would work with ChangeOrder().

            Please let us know if we may be of further assistance to you.

            Comment


              #7
              Thank you very much for the clear answer on this.

              Comment


                #8
                Originally posted by NinjaTrader_Kate View Post
                Hello localappleseed,

                Thank you for your posts.

                When creating strategies for use with TD Ameritrade, there are some important limitations to keep in mind.

                TD Ameritrade connections are particularly strict with NinjaScript strategies, especially with Native OCO enabled on the connection. TDA is also strict on the order in which they receive orders of different Order Actions. I.E. receiving a Buy before a Buy To Cover is received will result in a rejection.

                Once an OCO pair is submitted, it must be cancelled and replaced and TD Ameritrade will not allow modifying the orders. Set method orders cannot be canceled with CancelOrder(). Exit methods will not use OCO and can work around this limitation. (ExitLong(), for example).

                If a position is protected with working orders and NinjaTrader submits another order to exit the position, we can receive an Overbought/Oversold error.

                2020-06-03 13:50:59:743|1|32|Order='1132281582/AccountName' Name='Profit target' New state='Working' Instrument='IBM' Action='Buy to cover' Limit price=128.57 Stop price=0 Quantity=51 Type='Limit' Time in force=DAY Oco='1132281579:1371573263' Filled=0 Fill price=0 Error='No error' Native error=''

                2020-06-03 13:52:06:957|1|32|Order='4b0936b609014ef98df583e2e a3bce10/AccountName' Name='Buy to cover' New state='Rejected' Instrument='IBM' Action='Buy to cover' Limit price=0 Stop price=0 Quantity=51 Type='Market' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='Order rejected' Native error='This order may result in an oversold/overbought position in your account. Please check your position quantity and/or open orders.'

                Reversing orders may not work since NinjaTrader is multi threaded and it is possible for a Buy for a reversal to be submitted before the Buy To Cover order when reversing from a short position.

                There is also an on going issue where TDA has a delay on sending the Execution of an order after it fills.

                The above limitations are all specific to TD Ameritrade. You would need to cancel and resubmit any orders you need to change, and this would have a minor effect on performance, but I do not have a measurement of how much it would affect the performance compared to changing an order. It would likely be fairly negligible.

                Please let us know if we may be of further assistance to you.

                Thank you for this detailed summary of the limitations when working with TDA. Could you compare these situations with Interactive Brokers? I am testing a strategy that I use in futures, but I think it will have too many problems in equities with TDA/IBKR.

                Comment


                  #9
                  Hello rocker84,

                  Thank you for your reply.

                  Interactive Brokers does not have any of the limitations mentioned for TDA, all those would be specific to TDA connections. However, due to provider API design, Interactive Brokers connections do not guarantee the sequence of events of OnOrderUpdate, OnExecution, and OnPositionUpdate. This can lead to situations in which your script may not receive position updates as it should, leading to issues. The best way to deal with this would be to use the Unmanaged Approach and calculate the position internally to the strategy. I'm attaching an example script that demonstrates this approach.

                  Please let us know if we may be of further assistance to you.
                  Attached Files

                  Comment


                    #10
                    Originally posted by NinjaTrader_Kate View Post
                    Hello rocker84,

                    Thank you for your reply.

                    Interactive Brokers does not have any of the limitations mentioned for TDA, all those would be specific to TDA connections. However, due to provider API design, Interactive Brokers connections do not guarantee the sequence of events of OnOrderUpdate, OnExecution, and OnPositionUpdate. This can lead to situations in which your script may not receive position updates as it should, leading to issues. The best way to deal with this would be to use the Unmanaged Approach and calculate the position internally to the strategy. I'm attaching an example script that demonstrates this approach.

                    Please let us know if we may be of further assistance to you.
                    thanks! I will check that

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    85 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    48 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    29 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    32 views
                    0 likes
                    Last Post TheRealMorford  
                    Started by Mindset, 02-28-2026, 06:16 AM
                    0 responses
                    67 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Working...
                    X