Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

TD Signal Issue

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

    TD Signal Issue

    Ok, so with the input from everyone last week, I've made a lot improvements in a strategy I'm running Live at TD. I evaluate marketposition and this makes the trace output file super clean. So...

    Tuesday

    Script runs. Creates a market order with a Limit and Stop OCO, hits the profit target, cancels the stop order, updates Ninja - success.

    Creates another market order with a Limit and Stop OCO, hits the profit target, cancels the stop order, updates Ninja - success.

    Strategy hit its 1% profit for the day and makes no other trades.

    Wednesday (today)
    Script runs. Creates a market order with a Limit and Stop OCO, hits the profit target, cancels the stop order, updates Ninja - success.

    Creates another market order with a Limit and Stop OCO, hits the profit target, cancels the stop order, does not update Ninja. In TD, account is flat. In Ninja, it shows it is still working the Limit and Stop orders. Thirty minutes later, the market reverses which triggers an Exit within the strategy. Ninja attempts to close the order at TD, but is rejected as there is no open order. Ninja sends a cancellation request for the orders and then promptly shuts down the strategy.

    So, one, the Output file really shows nothing. It basically logs the PlaceOrders(), but does not log incoming limit notifications. The Log file does show this information for the first order that hit its profit target. The second order has no errors or anything in the log. It's almost like TD didn't send anything to Ninja to inform it of the limit execution and cancel of stop order.

    and two, we know that it can work. It's worked properly 3 times in the last 2 days. So, is this just a connection problem? Or is this an issue more specific with TD? Any insight is appreciated. My goal is leave this unattended.

    #2
    Hello sublime,

    Could you please send me your log and trace files for today. You can find these files at the following locations:

    Start Menu--> My Documents--> NinjaTrader 6.5--> Log--> log.20090218 for today. (log.yyyymmdd for any other date)

    Start Menu--> My Documents--> NinjaTrader 6.5--> Trace--> trace.20090218 for today. (trace.yyyymmdd for any other date)

    Please include an estimated time the profit target was hit for the second trade mentioned. You can send it to support[at]ninjatrader[dot]com, reference this thread and put 'Attn Jason' in the subject header.

    I will check if NinjaTrader has received a signal the profit target was filled/executed as well.
    JasonNinjaTrader Customer Service

    Comment


      #3
      Jason, I sent it.

      Comment


        #4
        Hello sublime,

        Thank you, please see my response to your email.
        JasonNinjaTrader Customer Service

        Comment


          #5
          More TD Issues

          Ok, I ran the same strategy on Friday.

          At 8:33 it opens a position and Buys the QID
          At 8:34 the position is filled
          At 8:35 ERROR: Cbi.MarketData.StartNow: exception caught: Item has already been added. Key in dictionary: 'QID' Key being added: 'QID'
          At 8:37 the Profit Target and Stop orders are filled. Seems like a delay.
          At 8:57 Market turns against strategy and triggers a Close order.
          At 8:57 Order is rejected with the following:
          Your order(s) can't be placed. The total quantity of outstanding open sell order(s) exceeds the quantity you hold.'

          At 8:57 Strategy shuts down.

          The close order is not received by TD so the order along with the Stop Limit and Profit Target are still working. I manually track the order and close the order at 12:16pm. Interesting part here. In TD, I do not close the stop limit or profit target orders, I simply right click the open position and select "Close". I notice a quick message that also says the "quantity exceeds the quantity I hold"...or something like that. TD then ignored the error and closed the position along with the limit and stop orders. Ninja was still connected to TD and recorded the trade and updated the position. So, I'm not sure what to make of that...

          I have noticed that a close initiated by Ninja has never worked in the live account with TD. My prior post about the limit order in TD not updating Ninja has worked before, but is not consistent.

          I will forward all logs and traces for Friday to Jason Hilling.

          Comment


            #6
            Hello sublime,

            I will await the files and start investigating.

            Can you please ensure you setup the TD AMERITRADE connection as per the instructions at the link below.
            JasonNinjaTrader Customer Service

            Comment


              #7
              I'm having the same issue. Did you ever find a solution for this?

              Comment


                #8
                Hi,

                Jason is out for the rest of the day. I will ask him to follow up tomorrow.

                Perhaps you can send an email directly to support at ninjatrader dot com and refer to this post. That way we can contact you directly.
                Vince B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello toptrader,

                  Can you please tell me what exact issue you experience.

                  Unfortunately I cannot recall the case and I could not find any reference in my documentation.
                  JasonNinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by toptrader View Post
                    I'm having the same issue. Did you ever find a solution for this?
                    Well, Toptrader, I think your experience tells me that the issue is not fixed. The problem resides with the SetProfitTarget() method used in conjunction with the TD adapter.

                    Let me give you a scenario. You create a strategy with SetProfitTarget() to .01 or 1% and a SetStopLoss() at .05 or 5%. Your strategy also has logic to invoke an ExitLong() in the OnBarUpdate() to exit a trade if the market goes against you.

                    So, as you enter a trade everything should execute just fine. Your are long XYZ with a limit and stop order which are OCO. If you hit the limit order, everything again should work. This limit order gets filled and the Stop order is cancelled. Works like a champ.

                    The problem occurs if in the same scenario, instead of your limit order being hit, the market moves against you and the OnBarUpdate() calls the ExitLong() method. Everything explodes and the strategy shuts down.

                    The "error" from TD states the "quantity exceeds the quantity you hold". Why? Because you already have a sell order in TD with your active OCO orders. So in reality, when you introduce another sell order by sending the ExitLong() to TD, you are attempting to sell more shares than you currently own. If you attempt the same thing trading on the TD site, you will get the same error...I've tried it. I had a live OCO order with both a limit and a stop, and then I attempted to sell the security... it wouldn't let me and gave me the same error. So, the error really has nothing to do with NT per se. Its happening at TD and relaying it to NT through the adapter.

                    What I thought would happen, would that the ExitLong() would somehow tell TD to cancel the OCO orders and sell the security. Well, that doesn't happen. I was originally told this was an issue with how TD handled orders created through the SetProfitTarget() method.

                    There is also an issue with the TDA adapter that requires OCO pairs to be submitted together. What this means is that you cannot use the Set() methods separately. See post below:



                    There are some potential ways around this. One I tried is to not use the SetProfitTarget() and just create the Limit order through the ExitLongLimit(). It's easy enough, you just have to first calculate the limit and call it after your EnterLong() in the OnBarUpdate. If the Limit order is hit... everything is fine. If the market moves against you and you want to Exit the position, you have a couple of options. You can cancel the Limit order, then exit the position with an ExitLong(). However, you need to take into account that your Limit order could get executed while trying to do this. (you can check).

                    Or you can do something a bit more complicated. You can modify the ExitLongLimit() so you force it to execute immediatelly. Sounds easy, but its a bit tricky. Since you have to wait for the position to be long before you can invoke a limit order, you have to call the ExitLongLimit() in the OnPositionUpdate() while looking for a long position. This works like a champ in creating the limit order. And once again, if the limit is hit...everything works great. The problem again happens when the market turns against you. You then have to force the limit to execute by modifying the ExitLongLimit() order to below the market price. Just make sure its not too low or TD will balk and post a question through the adapter that will leave your order in a pendingsubmit status. Just make it no more than 10% below the current market price. When your ExitLongLimit() begins to execute, another problem can happen.
                    Since large orders can get broken up into several partial fills, when fired, the OnPositionUpdate() will take the remaining long shares and actually modify the ExitLongLimit() submitting another order. Really screws things up. Just evaluate the share size in the OnPositionUpdate() and ignore if the shares are less than the original position.

                    So those are some of the ways around the issue. And they actually work. It's just a shame that you have to basically be a developer to get orders through the TD Adapter. Obviously, the strategy wizard won't be able to handle the demands of the TD adapter. But this is where my story ends. I had a 3 month lease and I just ran out of time. I would love to work out every kink, but I was getting killed on two ends. One, paying NT to debug the Adapter and, two, losing money on TD because TD does not have demo accounts, you have to trade live and, Three, opportunity cost and spending my time on solutions that already work.

                    However, that said, I also had some core strategy issues to sort out. Even if the TD Adapter did work with my code, my strategies were so complex, they were basically not backtestable. I had multi-instrument, multi-timeframe, multi-indicator combinations that just were too much. So I took a couple months, retraced my work and went down simpler paths to achieve reliable results. I've ended up with several strategies that work very well. Strategies that I can run live, then backtest the same day and get the same result.

                    Now I'm back and ready to implement. I went the direction of IB and it has worked well. I've not gotten one error and everything works perfect. My only issue is that its hard to leave that low TD commission behind. Since my time away, I've noticed that the TD connection has become much more reliable. I know TD did a lot of server upgrades that caused a lot of problems, but for the last several months the connection has been very reliable. I think with my simpler strategy, I can handle adding a little more complexity to try and get TD working. I can't tell you how happy I would be to get the exit orders working consistently and realiably. I really want to get it to work... and if I do... expect a huge post telling everyone how to do it!

                    I'll let you know what I come up with....

                    Comment


                      #11
                      Sublime,
                      Thank you for your informative response. Unforutnately I am not using any of the set methods. I use market orders for entries and place a stop. No limits at all. Yet TDA tells me my outstanding orders exceed my max position size. Any other suggestions?

                      Comment


                        #12
                        Originally posted by toptrader View Post
                        Sublime,
                        Thank you for your informative response. Unforutnately I am not using any of the set methods. I use market orders for entries and place a stop. No limits at all. Yet TDA tells me my outstanding orders exceed my max position size. Any other suggestions?
                        Well, if you create a Stop, regardless of what method you use, either SetStopLoss(), ExitLongStop(), ExitLongStopLoss() or whatever, .... it is an active sell order in TD. If you then try to close the position without first canceling your Stop, you will get the error message.

                        Comment


                          #13
                          Originally posted by sublime View Post
                          Well, if you create a Stop, regardless of what method you use, either SetStopLoss(), ExitLongStop(), ExitLongStopLoss() or whatever, .... it is an active sell order in TD. If you then try to close the position without first canceling your Stop, you will get the error message.
                          makes sense. thanks for your help.

                          Comment


                            #14
                            I am now cancelling the stop before I send my entry order, however I have the same issue. Anymore ideas?

                            Comment


                              #15
                              Originally posted by toptrader View Post
                              I am now cancelling the stop before I send my entry order, however I have the same issue. Anymore ideas?
                              I think you mean that you are cancelling the stop order before you send your exit order. Right? Are you monitoring to make sure the order is cancelled before you send the ExitLong()? Because if all your sell orders are cancelled.. you should not get that specific error.

                              For instance... check your trace file...and check to see you are getting confirmation of the cancel before you send the exitlong().
                              Last edited by sublime; 07-02-2009, 11:17 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Mongo, Yesterday, 11:05 AM
                              6 responses
                              27 views
                              0 likes
                              Last Post Mongo
                              by Mongo
                               
                              Started by ct, 05-07-2023, 12:31 PM
                              7 responses
                              206 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by wzgy0920, Yesterday, 09:53 PM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by Rapine Heihei, Yesterday, 07:51 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by kaywai, Today, 06:26 AM
                              1 response
                              6 views
                              0 likes
                              Last Post kaywai
                              by kaywai
                               
                              Working...
                              X