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

ExitLong() not removing order.

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

    ExitLong() not removing order.

    I'm using ExitLong() to sell my position and the sell is actually happening, but the order/position is not actually removed. See at about 36 seconds in on this video that the exit order takes place, but the order on the chart remains.

    Code:
    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0) return;
    if (CurrentBar < BarsRequiredToTrade) return;
    
    if (BuyCondition()
    )
    {
    EnterLong(quantitySelected);
    return;
    }
    
    if (currentPosition == null || currentPosition.Quantity == 0) return;
    
    if (SellConditionOne())
    {
    ExitLong();
    }
    
    if (ConvertToDecimal(Close[0]) <= ConvertToDecimal(currentPosition.AveragePrice))
    {
    ExitLong();
    }
    
    if (ConvertToDecimal(Close[0]) < ConvertToDecimal(currentPosition.AveragePrice * .995))
    {
    ExitLong();
    }
    }
    Last edited by clabough; 09-14-2021, 03:00 PM.

    #2
    Hi clabough, thanks for posting.

    This is unfortunately a TDA API issue where position information is not seen and NinjaTrader cannot properly react to the position change. The platform would need to be restarted when this happens while connected to TDA. There are other stock brokers such as Interactive Brokers (publicly available) that are not subject to this position update issue that TDA has with NinjaTrader 8.

    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Can I manually (through code) tell NT8 to remove that position? NT8 is telling TDA to sell and TDA sells and OnPositionUpdate reflects 0 shares, so NT8 should have a way to remove that position. Without this, I'd have to restart the platform every time NT8 issues a sell order.

      BTW, the position does go away with the next Buy order, so somehow NT8 figured out that it's an invalid position.
      Last edited by clabough; 09-14-2021, 03:30 PM.

      Comment


        #4
        Hi clabough,

        The only way to clear that is to restart the platform. I will report this incident to our development team so they can know it has caused further impact of TDA users.

        Kind regards.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          So this affects every TDA user? Are there that few that nobody else has complained about this very common scenario? I'd switch to IB, but with their requirement to have IBKR Pro to use the API, it's not cost-effective for me.

          Comment


            #6
            Hi clabough,

            I have seen this reported from users running custom strategies on their TDA accounts through NinjaTrader.

            Kind regards,
            -ChrisL
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              This seems like a critical bug. Is there any other workaround you can think of? If I have strategies running on other instruments at the same time, restarting would mess those up if they're currently in positions.

              I missed a lot of money today because the strategy won't re-enter because it already thinks it is in a position.

              Can I submit some kind of fake order to get it to clear and trap the error that's returned from TDA so that the strategy keeps working?

              Comment


                #8
                Hi clabough,

                The issue is with the TDA connection not updating the strategy position. We have implemented the connection per their API documentation so there is no workaround for this one. I have submitted the impact to our development team.

                Kind regards.
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  This is also happening for manual orders. In this video, I buy, then sell, but the order remains on the screen with the PnL still changing after I've sold.

                  Comment


                    #10
                    Hi clabough,

                    The issue is on TDAs side. We have done all we could to mitigate this issue on our order routing side.

                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      Maybe you should disclose all these limitations before someone spends $1100 on the product. I've written .NET/C# programs against the TDA API and can tell when I've bought/sold and what the current account position is. I bought NT8 because I didn't want to write all my own charting and order tracking. I thought with NT8 I could just write my custom strategies and be good.

                      My manager is a Microsoft Regional Director and there are many Microsoft MVPs at my company. I have a developer podcast that has thousands of listeners and thought of promoting NT, but won't do that with these kinds of problems. Maybe the decision-makers should be worried about word-of-mouth. It can be the best kind of advertising or the worst.

                      Comment


                        #12
                        Can I get around this problem with an unmanaged approach?

                        Comment


                          #13
                          Hi clabough, I do apologize.

                          The issue would still persist in the unmanaged mode. It's a problem that has been confirmed by the TD Ameritrade API team as being an issue on their end. Our colleague and support manager has responded on the same reported case here:
                          https://ninjatrader.com/support/foru...rs#post1141116

                          Chris L.NinjaTrader Customer Service

                          Comment


                            #14
                            If NT can reconcile the account status on startup, then it could reconcile the account status through a function call in code. I could make a video of my own test project handling this just fine through TD Ameritrade's API, but I don't think that would make any difference to you guys. It's not an issue on "their end" that can't be solved on your end.

                            Comment


                              #15
                              Just to be clear. The orders to buy and sell did get sent to TDA and were successful. The only thing is that NT didn't remove the order upon selling. If people can't buy and sell through custom strategies and they can't buy and sell by manually pressing the buy and sell buttons without issues, then it seems the whole TDA connector is broken.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by lakman184, Today, 03:09 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Started by romintrio, Today, 02:16 AM
                              1 response
                              4 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Started by SCC74, Today, 01:32 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Started by sidlercom80, Today, 01:57 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post sidlercom80  
                              Started by kevinenergy, Today, 01:17 AM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Working...
                              X