Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Automation issue with TD

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

    Automation issue with TD

    Started my live trading on TD this week with a couple of glitches. Yesterday my orders were rejected because they were GTC instead of Day. I corrected this and started anew this morning. The order fired through and executed fine. However it did not create the Profit Target or Stop Loss orders. I quickly logged into my TD account and confirmed that no other orders were created. Is there a simple reason for the non-creation of these orders? When it does work, I will be able to see these Limit orders in Ninja, correct?

    I will note that I've done extensive backtesting on this strategy. I also ran it in simulation for a month and everything worked fine. Hope this is an easy one.

    #2
    sublime,

    You will want to run your strategy with TraceOrders = true and also isolate your profit target logic with Print statements. If an order was actually placed you will get an output and a reason as to why it was rejected. Otherwise you know your code never went into that code block.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I'll make sure to do that. However this worked 100% in simulation, so I'm thinking its more of a syntax or setting issue, than a logic issue.

      I create the Target and Stop Loss orders in the Initialize()

      SetProfitTarget("MT3QLDOpen", CalculationMode.Percent, profit);
      SetStopLoss("MT3QLDOpen", CalculationMode.Percent, StopLoss, true);

      and then my OnBarUpdate() calls the EnterLong as

      {
      EnterLong(DefaultQuantity,
      "MT3QLDOpen");
      }

      and we know its hitting the EnterLong as the Buy is executed successfully.

      Comment


        #4
        You have to TraceOrders it to see why your order was rejected or not received or anything along those lines. If your order was actually submitted you will receive some print lines to inform you of this.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Day 2 update. So I put TraceOrders = True in my code and reviewed the Output. The output actually showed no errors, but the log told me that my account had *express trading* disabled. I fixed that at TD, but to no avail. The Buy and Sell orders are being sent to TD fine. The limit orders are not. In the Orders tab, the strategy actually created the stop order and profit target order, but did not send them to TD.

          The Stop Limit order has a status of *Initialize* and the Profit target order has a status of *PendingSubmit*

          I'm wondering...I have *Orders per direction* set at 1. Is that preventing them from being sent? I thought that parameter applied only to opening positions.

          Any further insight?

          Comment


            #6
            Please post the actual TraceOrders log for the relevant point in time.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Automation issue with TD

              Ok... attached is a small portion of the Output log. It's a little crazy as this is a multi-timeframe, multi-instrument strategy. From a pure debugging standpoint I'm going to add logic to not even hit the trade block if a position is already open. It would cut this log down by 80%. And it looks as if the strategy thinks the position is closed, therefore it kills the stop order. But your expertise is needed.

              I will also say that the initialize block has a profit and stop order per instrument. Not sure if this is a problem.

              SetProfitTarget("MT3QLDOpen", CalculationMode.Percent, profit);
              SetProfitTarget(
              "MT3QIDOpen", CalculationMode.Percent, profit);
              SetStopLoss(
              "MT3QLDOpen", CalculationMode.Percent, StopLoss, true);
              SetStopLoss(
              "MT3QIDOpen", CalculationMode.Percent, StopLoss, true);

              Thanks for the help guys.
              Attached Files

              Comment


                #8
                Yes, the strategy ignores the the stop / target order as no position to exit from exists. Did you recheck your various signal names to match up?

                Multiple SetStopLoss and SetProfitTarget calls are ok, as long as you use unique signal names per position and instrument.

                Comment


                  #9
                  Yes, they are unique signal names per position and instrument, however I've combined some of the redundant code which might be confusing TD. Such as:

                  if (BarsInProgress ==0 || BarsInProgress==2)
                  {
                  if ((MACD(BarsArray[0],12, 26, 9).Diff[0] > .02) && (MACD(BarsArray[2],12, 26, 9).Diff[0] > 0))
                  {
                  EnterLong(DefaultQuantity, "MT3QLDOpen");
                  }
                  }

                  The 0 and 2 BarsArray are the same instrument, just at different time periods.

                  I'll do two things. Simplify the code to try and avert any confusion. I'll also do a live test of a very simple strategy I have with profit and stop targets to ensure its the code and not something at TD.

                  I'll add that there is definitely a position to set a profit and stop price and it has not been closed. Additionally, when the close signal is triggered, the strategy successfully closes the position.
                  Last edited by sublime; 02-12-2009, 08:17 AM.

                  Comment


                    #10
                    sublime,

                    You need to step through your code and ensure the positions with the correct signal names exists at the time you place the Set() methods. From your logs it is evident you are sending Set() methods when there are no positions. Furthermore you start running into these: Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties' which suggests your signal names to be wrong earlier.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Here is how I'm interpreting the Output log.

                      Understand that the two instruments are inverse to each other (QLD, QID) So when one instrument is approaching a buy signal, the other instrument is firing exit signals.

                      1. The program hits the Entry signal for QLD and buys QLD.

                      2. In the same bar, the program hits the ExitLong block of code for QID, however there is no position.

                      3. For some reason, it confuses the fact that there is no position in QID, and therefore kills the profit and target orders for the QLD position.

                      Even with unique names, it looks like that's what's happening.

                      Comment


                        #12
                        Not sure I follow. Don't submit ExitLong()s if you don't have the position.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Well the reason it has all the exceeds positions messages is that I don't have logic that checks to see if the strategy is already in a position. I merely kill it at the strategy window by setting "Entries per Direction" to 1. So it will continue to try and create a position as long as the entry criteria is true. It makes the log super big, so I will add that logic to not even hit the Set() if already in a position. Maybe that will clear all of it up.

                          Comment


                            #14
                            Yes, I'll do this. I knew the program would ignore the Exit call if no position existed, so I didn't worry about building MarketPosition qualifying logic. I just didn't think it would mess up other parts of the program.

                            Comment


                              #15
                              sublime,

                              It doesn't mess it up, but when your logs are flooded with traces of those ignores it becomes extremely difficult to track down what is causing the issue.
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              110 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              59 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              37 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              41 views
                              0 likes
                              Last Post TheRealMorford  
                              Started by Mindset, 02-28-2026, 06:16 AM
                              0 responses
                              78 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Working...
                              X