Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetAtmStrategyStopTargetOrderStatus not working right ?

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

    GetAtmStrategyStopTargetOrderStatus not working right ?

    I am automating an ATM strategy that when an entry order fills, creates 2 exits (OCO), a target and a stop.

    so after my target is filled, I call :
    string[,] orders = GetAtmStrategyStopTargetOrderStatus("TARGET1", "idValue");

    I am trying to find out if the order has filled with a target, so I am calling the above function to get the multidimensional array return value that I can iterate through and check for an OrderState value.

    However, when I call the function, if the order has already reached it's target I get an error in the Console Log saying :

    GetAtmStrategyStopTargetOrderStatus() method error : AtmStrategyID '5878' does not exist or is already in terminated state. (note id 5878 is an id value I assigned my atm strategy).

    So basically it seems there's no way to check if an ATM strategy has reached its TARGET1, since when it reaches the target, you can no longer use GetAtmStrategyStopTargetOrderStatus() to check for a Filled status on the TARGET1 ?

    Please, I need a real developer to answer this question, not just a reply to a link to the documentation, which I've read several times over and is severely lacking in detail.

    thanks,
    jose mera

    #2
    Please post complete code. Please also make sure you have not reset your variables to string.Empty.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Code is bellow.

      Note orderID and atmID are the ids generated for the atm creation :
      atmID = currentLowPivot.ToString();
      orderID = GetAtmStrategyUniqueId();
      // issue new order
      AtmStrategyCreate (Action.Sell,
      OrderType.Stop, 0, Low[lowBarsAgo],
      TimeInForce.Day, orderID,
      aTMName, atmID);

      they are private member variables and do not get reset to string.Empty before calling the function bellow. I know this because in the error message in the Console Log (refer to my first post), it says that the atm strategy ID does not exist. Please read my first post more carefully. If the id was Empty, the error message would not be referring to the id value of '5878'.

      The function bellow is the function that is trying to check for a fill status :

      protected bool IsOrderClosed()
      {
      //nothing to do if entry order not filled
      Print("\t\tOrder with orderID " + orderID + " is : " + GetAtmStrategyEntryOrderStatus(orderID)[2].ToString());
      if( GetAtmStrategyEntryOrderStatus(orderID)[2] != OrderState.Filled.ToString()) return false;

      Print ("\tChecking for closed order with atmID = " + atmID);
      string[,] orders = GetAtmStrategyStopTargetOrderStatus("TARGET1", atmID);
      // Check length to ensure that returned array holds order information
      if (orders.Length > 0) {
      Print("\t\tClosed order with TARGET1 found, checking for fill status...");
      // first check for a target fill
      bool partialFillFound = false;
      int filledCount = 0;
      int numOfOrders = orders.GetLength(0) - 1;
      for (int i = 0; i < numOfOrders; i++) {
      Print("\t\t\tatmID(" + atmID + " : current state is " + orders[i, 2].ToString() + " -- contract #" + (i+1));
      if (orders[i,2] == OrderState.Filled.ToString()) {
      filledCount++;
      } else if (orders[i,2] == OrderState.PartFilled.ToString()) {
      partialFillFound = true;
      Print("\t\t\tFound Partial Fill");
      }
      }

      if (filledCount != numOfOrders || partialFillFound) {
      // force a close order
      Print("\t\tClosing Order");
      bool success = AtmStrategyClose(atmID);
      if (!success) Print ("\t\t\tfailed to find AtmOrderId: " + atmID + " when attempting to close");
      return true;
      }
      }

      // now check for a stop loss fill
      string[,] orders2 = GetAtmStrategyStopTargetOrderStatus("STOP1", atmID);
      // assume that when stop loss is hit, all contracts fill since it's a stop order
      if (orders2.Length > 0) {
      Print ("\t\tClosed order with STOP1 found");
      return true;
      } else {
      Print("\t\tOrder with atmID = " + atmID + " has not closed");
      return false;
      }
      }

      Comment


        #4
        int numOfOrders = orders.GetLength(0) - 1;
        Should not be -1.
        Attached Files
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          It's funny you mention that, because I got the
          "int numOfOrders = orders.GetLength(0) - 1;" line from your documentation, maybe you guys should fix your docs, huh ?

          In any case, changing that line doesn't affect the problem I am having. The problem lies with the call to
          GetAtmStrategyStopTargetOrderStatus("TARGET1", atmID);
          which returns an error once the atm strategy has reached its target and closed. Again, it seems that this is the intended behavior and your poor documentation doesn't explain that.

          So I'll ask again, is there any way to verify through an atm API call that all the atm strategy has reached a target or stop 100% and is no longer working ?

          Comment


            #6
            documentation

            BTW, here is a link to your docs with that bad line of code so you can fix it :



            I've found other obvious errors in your docs before, maybe you guys should be a little more serious about documenting your APIs. How do you expect us to be able to take your platform seriously if you can't explain how your stuff works ?

            Comment


              #7
              pepelucho,

              Documentation is taken very seriously. If there is an error/typo then there is an error. This one has already been noted before and is already addressed in NT7 documentation.

              Use the attached strategy in my previous post to see it working as expected. You need to debug what is different from your setup versus what I have provided.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Josh,

                I am a software engineer with 10 years of programming experience. I am not new to coding. if you took your documentation seriously, you would have fixed your NT6 docs already since that is what every body is using *at the present time* !

                As far as your example, it doesn't help. I've debugged my code and the problem lies on your API call. If you had read my 1st post carefully, you would have seen that the error message

                "GetAtmStrategyStopTargetOrderStatus() method error : AtmStrategyID '5878' does not exist or is already in terminated state. (note id 5878 is an id value I assigned my atm strategy)."

                imples that you cannot call this function on an ATM strategy that has reached its target or stop 100%, that is "or in already in terminated state".

                It's not a bug in my code, it's another example of poor documentation. There should be an explanation saying that this function can only be used on ATM strategies that haven't had a 100% closing fill.

                So again, I ask, how can I check if an ATM strategy has closed 100% ?

                Comment


                  #9
                  Please accept our apologies in regards to the documentation bugs.

                  As with any (software) component, documentation has bugs. This is a fact. As Josh stated the bug you reported has already been addressed with the next major upgrade of our software (which is NT7, non-public beta right now). It's the nature of software business that non-critical bugs may be resolved only on a major upgrade. This is what we did.

                  Josh will follow up on the very issue itself.

                  Comment


                    #10
                    Ok, I understand that. That's what I wanted to hear from josh, that it was a problem on your side and not my 'buggy code'

                    But my quesiton still hasn't been answered. Could you provide me with a work around so that I have a way to verify that an ATM strategy has closed with all contracts filled ?

                    thanks.

                    Comment


                      #11
                      One more note that I want to point out.

                      I was using TradeStation until a few months ago when I switched to NT.
                      Tradestation is a lousy platform for automation, so I decided to try NT.

                      Ninjascript is miles ahead of easylanguage, however completely lags TS in helping users. Your docs are of poor quality, your forums just seems to consist of replies with the same code examples, and there's no serious help to developers like myself.

                      When I was with TS and posted a problem, I would get a phone call from a senior engineer to talk to me about the issue when it was serious enough. With NT, it seems I have to get all angry and stuff just to get you to admit that your stuff is wrong, and still don't get any help as to how to work around bugs in your platform.

                      my 2 cents.

                      Comment


                        #12
                        pepelucho,

                        If you tried the code I provided you will find that the call itself works as expected. It properly returns filled states for whichever order gets filled. No errors received till you start running subsequent checks of the now empty AtmStrategyId.

                        You should try the reference first and confirm it works on your end first to establish this base scenario. If you experience otherwise then please provide how exactly you get different behavior and what that different behavior is.

                        Example output of when stop gets filled:
                        Target Average fill price is 0
                        Target Filled amount is 0
                        Target Current state is PendingCancel
                        Stop Average fill price is 1086.25
                        Stop Filled amount is 1
                        Stop Current state is Filled
                        ----------------

                        Example output of when target gets filled:
                        Target Average fill price is 1087.75
                        Target Filled amount is 1
                        Target Current state is Filled
                        Stop Average fill price is 0
                        Stop Filled amount is 0
                        Stop Current state is PendingCancel
                        ----------------
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Ok, thanks josh, I will try that and I apologize for getting agro.

                          Comment


                            #14
                            Just a note on your output example,

                            for both the stop and target, there is still a 'pendingcancel" status, meaning the ATM strategy is still working and alive until that cancel happens and the ATM stops working.

                            In my case, I call GetAtmStrategyStopTargetOrderStatus() to check if the ATM strategy has closed *completely*, without any pendings - meaning every single contract in that ATM strategy has filled with either a stop or a target and there are no pendings left on any contract.

                            again, I will reiterate, look at the error message that I posted that shows up in the console log. It is complaining about an atmID that does not exist. If I was passing an Empty value to it, it would not show the atmID in the error message.

                            so the way I see it, once an atm position is completely closed (no pendings left on any contracts), you can no longer call GetAtmStrategyStopTargetOrderStatus() in order to see how the exit fills happened.

                            That's all I am asking, for you guys to confirm that this is how it works. The error message itself says calling the function on an ATM strategy that is in 'terminated state' is an error.

                            Cant you guys just send this along to one of your developers who can look at the code and confirm this ?

                            Comment


                              #15
                              You need to check for the filled state of one of the orders and not for a cancelled state. You do not receive a cancelled state since as you have noted the ATM is already terminal and inaccessible. The filled state on one of them is the last state you will receive.

                              Development has informed me this is a current limitation.
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              648 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              369 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              108 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              572 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              574 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X