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

TD Ameritrade compatibility?

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

    TD Ameritrade compatibility?

    I have a multi-instrument strategy that uses minute data. The primary bars are 1 minute US Equities RTH and the supporting bars are 5 minute US Equities ETH.

    I would like to turn this strategy on to run against my TD Ameritrade brokrage account.

    Based on the data provided by TD Ameritrade, Do you see issues with this strategy running against the TD Ameritrade brokerage?

    From looking at this:​ https://ninjatrader.com/support/help...y_provider.htm - I am not sure?

    State.Configure code:

    Code:
    else if (State == State.Configure) {
    
            //Add daily Volitility bars
            AddDataSeries("^VIX", BarsPeriodType.Day, 1);
    
            //Add Premarket Bars.
            var SymArr = this.Symbols.Split(',');
            foreach (var sym in SymArr) {
                AddDataSeries(sym, new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 5 }, "US Equities ETH");
            }
    }​
    Thanks,
    Erik

    #2
    Hello Erik,

    As a heads up, using dynamic variables in AddDataSeries() is officially not supported.

    From the help guide:
    "Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result in an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner."


    That said, note with TDA the manage approach uses the StopTargetHandling ByStrategyPosition. Should the strategy place more than one entry order, set methods cannot be used as this would cause the stop loss quantity to update, which will fail with TDA due to OCO.

    From the help guide:
    "Warning: If your strategy executes to an Interactive Brokers or TD Ameritrade account, the StopTargetHandling will always be forced to .ByStrategyPosition"


    This means use the unmanaged approach should you need multiple entries using OCO with the exits.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Thanks for the reply.

      If I change it to this, is it supported?

      Code:
      else if (State == State.Configure) {
      
              //Add daily Volitility bars
              AddDataSeries("^VIX", BarsPeriodType.Day, 1);
      
              //Add Premarket Bars.
              var Symbols = "AAPL,TSLA,AMZN,NVDA";
              var SymArr = Symbols.Split(',');
              foreach (var sym in SymArr) {
                  AddDataSeries(sym, new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 5 }, "US Equities ETH");
              }
      }​
      Thanks,
      Erik

      Comment


        #4
        Hi Chelsea,

        As for the TD Ameritrade question. I was wondering if I have a 1 minute US Equities RTH​ strategy running. Will the added 5 minute US Equities ETH bars be available to check premarket data, like when I am back testing the strategy? I am only placing trades against the primary 1 minute US Equities RTH​​ bars.

        I will look into the StopTargetHandling link you posted to try to understand that.

        Thanks,
        Erik​

        Comment


          #5
          Hello Erik,

          No, using variables in AddDataSeries() is not supported. Your loop that uses variables is not supported.

          To confirm, have you read the help guide on AddDataSeries()?

          From the help guide:
          "If your NinjaScript object is using AddDataSeries() allowing to specify a tradingHoursName, please keep in mind that: An indicator / strategy with multiple DataSeries of the same instrument will only process realtime OnBarUpdate() calls when a tick occurs in session of the trading hour template of all added series. Any ticks not processed will be queued and processed as a tick comes in for all subsequent DataSeries."


          You can add the series with a different trading hours template. But data won't be processed until all series are session.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hi Chelsea,

            Does this fix the "using variables" issue?

            Code:
            else if (State == State.Configure) {
            
                    //Add daily Volitility bars
                    AddDataSeries("^VIX", BarsPeriodType.Day, 1);
            
                    //Add Premarket Bars.
                    AddDataSeries("AAPL", new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 5 }, "US Equities ETH");
                    AddDataSeries("TSLA", new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 5 }, "US Equities ETH");
                    AddDataSeries("AMZN", new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 5 }, "US Equities ETH");
                    AddDataSeries("NVDA", new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 5 }, "US Equities ETH");
            
            }​

            Thanks,
            Erik

            Comment


              #7
              Hello Erik,

              Yes, this removes the use of variables and is no longer a dynamic call to AddDataSeries().
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hi Chelsea,

                Thank you for the very quick reply!

                My main question has to do with going from back testing and optimizing to a live data feed against TD Ameritrade.

                I am back testing using downloaded historical minute data.

                Primary data series is SPY 1 minute RTH

                Other data series are setup from the code you just reviewed.

                The strategy uses a moving average of the VIX to get a general volatility level of the market.

                The other ETH series are used to check the premarket volume before the first SPY bar is available for the RTH.

                Will these ETH bars be available from TD Ameritrade data feed, so the strategy can check the premarket volume?

                Thanks,
                Erik
                Last edited by ErikHR1969; 10-28-2022, 10:57 AM.

                Comment


                  #9
                  Hello Erik,

                  I would recommend that you open a chart and set the hours template and confirm for any broker or data feed you are connected to, what data you are getting.

                  From my understanding TDA provides ETH data for equities, but likely not indexes, however I would not have an account to test and confirm.

                  Please contact TD Ameritrade if you have questions about the data they have available.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi Chelsea,

                    I have read the links you have provided and many other posts about TDA on the forum. Do you or someone in the support team have a current know TDA brokerage API issues list. Trying to pilfer though all of the posts is quite tedious, and it is hard to tell what has been resolved and what the open issues are.
                    I have been using NinjaTrader for a long time for testing strategies. Years ago, I purchased a live license to use against TDA, that did not work well (too many live issues). I have some more strategies I would like to turn on, but I do not want an experience like my last one.

                    The example I am interested in starting with is:
                    Strategy: SPY 1-minute RTH (used to place buy or sell trades against SPY), with added ^VIX RTH daily bars (just need an average VIX value to measure volatility) and added 5-minute ETH bars for APPL, and GOOGL (just need to check some premarket volume before RTH starts)?

                    This example works perfectly fine back testing with historical downloaded data.

                    My question is: Based on TDA know issues that you or the developers are aware of, do you/they see anything that may cause issues with the example above if it was live against TDA?

                    Thanks,
                    Erik
                    Last edited by ErikHR1969; 11-11-2022, 05:36 PM.

                    Comment


                      #11
                      Hi Erik,

                      You did not ask me but I will offer up a quick "two cent" answer.

                      From my experience.
                      1. Run full scale, production ready testing via SIM during the Market Open and other busy times testing both Data Lag/Latency and connection Reliability are acceptable to you. .. also test / validate the usefulness the data Latency during less busy times.
                      2. Have a strong connection monitoring and emergence response plan in place.
                      3. There is/recently was a guy on Youtube streaming live trading of a NT8 real-time scalping auto-strategy running against a TDA connection.
                      Hedge

                      Comment


                        #12
                        Hello Erik,

                        I would not have a list of all TDA related bug reports but bugs and issues can affect any connection type.

                        We report these to our developers as clients report issues.

                        However, I am not understanding the issue. What is the error message you have received?
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hedge, Thanks for the tips.

                          Chelsea,

                          I opened an IB account too. If I buy NinjaTrader, I assume I can switch back and forth between IB and TDA if I have issues with one or the other. Is this correct?

                          Thanks,
                          Erik

                          Comment


                            #14
                            Hello Erik,

                            With a Multi-Broker license key you can connect to both brokers.
                            Chelsea B.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by rbeckmann05, Today, 06:48 PM
                            0 responses
                            1 view
                            0 likes
                            Last Post rbeckmann05  
                            Started by rhyminkevin, Today, 04:58 PM
                            4 responses
                            52 views
                            0 likes
                            Last Post dp8282
                            by dp8282
                             
                            Started by iceman2018, Today, 05:07 PM
                            0 responses
                            5 views
                            0 likes
                            Last Post iceman2018  
                            Started by lightsun47, Today, 03:51 PM
                            0 responses
                            7 views
                            0 likes
                            Last Post lightsun47  
                            Started by 00nevest, Today, 02:27 PM
                            1 response
                            14 views
                            0 likes
                            Last Post 00nevest  
                            Working...
                            X