Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with GetAtmStrategyStopTargetOrderStatus

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

    Problem with GetAtmStrategyStopTargetOrderStatus

    We are having problems with GetAtmStrategyStopTargetOrderStatus() not recognizing partial fills when GetAtmStrategyEntryOrderStatus is stating there are partial fills.
    I have attached a simple strategy that can repeat the condition when using GC 04-14 Market Replay data on 2/6/2014 @ 6:35am MST. Also attached are the Trace, Log, and Output Window files.

    When GetAtmStrategyStopTargetOrderStatus() does not recognizing partial fills it leaves open positions. The question is, how do we close those partial filled positions?
    Thanks,
    Zac
    SharkIndicators.com
    Attached Files
    zacwhitesi
    NinjaTrader Ecosystem Vendor - Shark Indicators

    #2
    Hello Zac,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    To clarify here, are you stating that the GetAtmStrategyStopTargetOrderStatus() is not reporting any filled orders when the entry orders have been filled? Or that it does not report fills when the Stop or Target has clearly been filled to close the positions?

    Comment


      #3
      Originally posted by NinjaTrader_PatrickH View Post
      ...are you stating that the GetAtmStrategyStopTargetOrderStatus() is not reporting any filled orders when the entry orders have been filled?
      Correct. The Stop or Target has Not been filled. The Entry has been filled.

      These commands are returning the following, before any Cancel or Close method is called...
      string[] EntOrders = GetAtmStrategyEntryOrderStatus(orderId);
      string[,] TargOrders = GetAtmStrategyStopTargetOrderStatus("TARGET1", orderId);
      string[,] StopOrders = GetAtmStrategyStopTargetOrderStatus("STOP1", orderId);

      From the Output Window:
      **NT** GetAtmStrategyStopTargetStatus() method error: AtmStrategyId '9c12796eda0b4d328ef39b97c146a00a' does not exist or is already in terminated state
      **NT** GetAtmStrategyStopTargetStatus() method error: AtmStrategyId '9c12796eda0b4d328ef39b97c146a00a' does not exist or is already in terminated state
      Attached Files
      Last edited by zacwhitesi; 02-25-2014, 12:03 PM.
      zacwhitesi
      NinjaTrader Ecosystem Vendor - Shark Indicators

      Comment


        #4
        Hello zacwhitesi,

        Thank you for your response.

        Are you setting an atmStrategyId as well? If not, please do so and then call that value in the GetAtmStrategyStopTargetOrderStatus() method:
        GetAtmStrategyStopTargetOrderStatus(string orderName, string AtmStrategyId)

        Comment


          #5
          Originally posted by NinjaTrader_PatrickH View Post
          Hello zacwhitesi,
          Are you setting an atmStrategyId as well? If not, please do so and then call that value in the GetAtmStrategyStopTargetOrderStatus() method:
          Yes. As you can see from the code given above, string orderId holds the atmStrategyId value.
          zacwhitesi
          NinjaTrader Ecosystem Vendor - Shark Indicators

          Comment


            #6
            Hello zacwhitesi,

            I meant like we see in the SampleAtmStrategy file (Tools > Edit NinjaScript > Strategy):
            Code:
            				atmStrategyId = GetAtmStrategyUniqueId();
            				orderId = GetAtmStrategyUniqueId();
            Please try using unique ids for the atmStrategyId and orderId.

            Comment


              #7
              Originally posted by NinjaTrader_PatrickH View Post
              Hello zacwhitesi,
              I meant like we see in the SampleAtmStrategy file (Tools > Edit NinjaScript > Strategy):
              Please try using unique ids for the atmStrategyId and orderId.
              The Strategy I posted in my first post shows that a unique ID is being requested. Sense you have not bothered to look at the code, I have posted the OnBarUpdate() section below. Thanks.
              Code:
                      protected override void OnBarUpdate()
                      {
                          if (Historical)
                              return;
                          
                              Print("OnBarUpdate: "+Time[0].ToString("HH:mm:ss")+"\tBar#: "+CurrentBar+" \t "+(Close[0]>Open[0]?"UP bar":"DOWN bar"));            
                          if (Slope(Close, 2, 1) < 0 && Slope(Close, 1, 0) > 0)    //Look for price to reverse up.
                          {
                              if (orderId != "") // If an orderID exists, then cancel it.
                              {
                                          Print (Time[0].ToString("HH:mm:ss")+" LONG state. Preparing to CANCEL ATM OrderID: "+orderId);
                                  CancelAllATM(orderId); // Method to cancel all pending & open positions.
                              }
                                      Print (Time[0].ToString("HH:mm:ss")+"   GetAtmStrategyUniqueId()");
                              [SIZE=3][B]orderId = GetAtmStrategyUniqueId();[/B][/SIZE]
                                      Print (Time[0].ToString("HH:mm:ss")+" Placing Long Limit at: "+(GetCurrentBid()-2*TickSize)+"\t OrderID: "+orderId);
                              AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, GetCurrentBid() - 2 * TickSize, 0, TimeInForce.Day, orderId, "Test", orderId);
                              orderPlaced = true; atmCncEtry = false; atmClose = false;
                          }
                          else if (Slope(Close, 2, 1) > 0 && Slope(Close, 1, 0) < 0)    //Look for price to reverse down.
                          {
                              if (orderId != "")
                              {
                                          Print (Time[0].ToString("HH:mm:ss")+" SHORT state. Preparing to CANCEL ATM OrderID: "+orderId);
                                  CancelAllATM(orderId);
                              }
                                      Print (Time[0].ToString("HH:mm:ss")+"   GetAtmStrategyUniqueId()");
                              [SIZE=3][B]orderId = GetAtmStrategyUniqueId();[/B][/SIZE]
                                      Print (Time[0].ToString("HH:mm:ss")+" Placing Short Limit at: "+(GetCurrentAsk()+2*TickSize)+"\t OrderID: "+orderId);
                              AtmStrategyCreate(Cbi.OrderAction.SellShort, OrderType.Limit, GetCurrentAsk() + 2 * TickSize, 0, TimeInForce.Day, orderId, "Test", orderId);
                              orderPlaced = true; atmCncEtry = false; atmClose = false;
                          }
                          else if(orderPlaced) //Cancel & Close the ATM on the next bar.
                          {
                                      Print (Time[0].ToString("HH:mm:ss")+" NO state. Preparing to CANCEL ATM OrderID: "+orderId);
                              CancelAllATM(orderId);
                              orderPlaced = false;
                          }
                     }
              The strategy(attached above) I built to show the problem was derived from the SampleAtmStrategy.
              Last edited by zacwhitesi; 02-25-2014, 06:32 PM.
              zacwhitesi
              NinjaTrader Ecosystem Vendor - Shark Indicators

              Comment


                #8
                Hello zacwhitesi,

                Thank you for your response.

                I am not explaining this clearly, my apologizes. Please use a unique id for both the atmStrategyId and the orderId, then call the atmStrategyId for the GetAtmStrategyStopTargetOrderStatus(string orderName, string AtmStrategyId) method.

                This means we use the GetAtmStrategyUniqueId() method to generate two strings; one for the entry order and one for the atm strategy itself.

                So we would have something more similar to the following:
                Code:
                			if (Slope(Close, 2, 1) < 0 && Slope(Close, 1, 0) > 0)	//Look for price to reverse up.
                			{
                				if (orderId != "") // If an orderID exists, then cancel it.
                				{
                							Print (Time[0].ToString("HH:mm:ss")+" LONG state. Preparing to CANCEL ATM OrderID: "+orderId);
                					CancelAllATM(orderId); // Method to cancel all pending & open positions.
                				}
                						Print (Time[0].ToString("HH:mm:ss")+"   GetAtmStrategyUniqueId()");
                				[B]orderId = GetAtmStrategyUniqueId();
                				atmStrategyId = GetAtmStrategyUniqueId();[/B]
                						Print (Time[0].ToString("HH:mm:ss")+" Placing Long Limit at: "+(GetCurrentBid()-2*TickSize)+"\t OrderID: "+orderId);
                				[B]AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, GetCurrentBid() - 2 * TickSize, 0, TimeInForce.Day, orderId, "Test", atmStrategyId);[/B]
                And then we would call the atmStrategyId for the status of the Stop and/or Target:
                Code:
                			string[] EntOrders = GetAtmStrategyEntryOrderStatus(orderId);
                			string[,] TargOrders = GetAtmStrategyStopTargetOrderStatus("TARGET1", atmStrategyId);
                			string[,] StopOrders = GetAtmStrategyStopTargetOrderStatus("STOP1", atmStrategyId);

                Comment


                  #9
                  Thanks for pointing that out Patrick.
                  I searched the forum first for the issue I'm having and came across an example strategy that NinjaTrader_JC posted here.. http://www.ninjatrader.com/support/f...0&postcount=18
                  I based my ATMtest strategy from JC's example,which only has..

                  if (!orderPlaced)
                  {
                  orderId = GetAtmStrategyUniqueId();
                  AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, GetCurrentBid() - 10 * TickSize, 0, TimeInForce.Day, orderId, "Test", "testStrategyIdValue");
                  orderPlaced = true;
                  }

                  I would suggest removing NinjaTrader_JC sample code sense it is incorrect compared to your example.
                  Thanks again,
                  Zac
                  zacwhitesi
                  NinjaTrader Ecosystem Vendor - Shark Indicators

                  Comment


                    #10
                    Hello Zac,

                    Thank you for your response.

                    The example JC provided (which is actually an update of the example provided by our CEO and founder Ray earlier in the thread: http://www.ninjatrader.com/support/f...25&postcount=8) is only intended to cancel the entry order, not check the values of the Stop and Target. I am actually referring to the SampleAtmStrategy available pre-loaded in NinjaTrader under Tools > Edit NinjaScript > Strategy > SampleAtmStrategy.
                    Last edited by NinjaTrader_PatrickH; 02-26-2014, 03:33 PM.

                    Comment


                      #11
                      Hi Patrick,
                      I implemented the changes you gave me, but the problem still persists. Below is the updated code.
                      Code:
                              protected override void OnBarUpdate()
                              {
                                  if (Historical)
                                      return;
                                  
                                      Print("OnBarUpdate: "+Time[0].ToString("HH:mm:ss")+"\tBar#: "+CurrentBar+" \t "+(Close[0]>Open[0]?"UP bar":"DOWN bar"));            
                                  if (Slope(Close, 2, 1) < 0 && Slope(Close, 1, 0) > 0)    //Look for price to reverse up.
                                  {
                                      if (orderId != "") // If an orderID exists, then cancel it.
                                      {
                                                  Print (Time[0].ToString("HH:mm:ss")+" LONG state. Preparing to CANCEL ATM OrderID: "+orderId);
                                          CancelAllATM(orderId, atmStrategyId); // Method to cancel all pending & open positions.
                                      }
                                      [B]orderId        = GetAtmStrategyUniqueId();[/B]
                                              Print (Time[0].ToString("HH:mm:ss")+"   GetAtmStrategyUniqueId() orderID: "+orderId);
                                      [B]atmStrategyId    = GetAtmStrategyUniqueId();[/B]
                                              Print (Time[0].ToString("HH:mm:ss")+"   GetAtmStrategyUniqueId() atmStrategyId: "+atmStrategyId);
                                      double lmtPrice = (GetCurrentBid()-2*TickSize);
                                              Print (Time[0].ToString("HH:mm:ss")+" Placing Long Limit at: "+lmtPrice+"\t OrderID: "+orderId+"\t atmStrategyId: "+atmStrategyId);
                                      AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, lmtPrice, 0, TimeInForce.Day, [B]orderId[/B], "Test", [B]atmStrategyId[/B]);
                                      orderPlaced = true; atmCncEtry = false; atmClose = false;
                                  }
                                  else if (Slope(Close, 2, 1) > 0 && Slope(Close, 1, 0) < 0)    //Look for price to reverse down.
                                  {
                                      if (orderId != "")
                                      {
                                                  Print (Time[0].ToString("HH:mm:ss")+" SHORT state. Preparing to CANCEL ATM OrderID: "+orderId);
                                          CancelAllATM(orderId, atmStrategyId);
                                      }
                                     [B] orderId        = GetAtmStrategyUniqueId();[/B]
                                              Print (Time[0].ToString("HH:mm:ss")+"   GetAtmStrategyUniqueId() orderID: "+orderId);
                                     [B] atmStrategyId    = GetAtmStrategyUniqueId();[/B]
                                              Print (Time[0].ToString("HH:mm:ss")+"   GetAtmStrategyUniqueId() atmStrategyId: "+atmStrategyId);
                                      double lmtPrice = (GetCurrentAsk()+2*TickSize);
                                              Print (Time[0].ToString("HH:mm:ss")+" Placing Short Limit at: "+lmtPrice+"\t OrderID: "+orderId+"\t atmStrategyId: "+atmStrategyId);
                                      AtmStrategyCreate(Cbi.OrderAction.SellShort, OrderType.Limit, lmtPrice, 0, TimeInForce.Day, [B]orderId[/B], "Test", [B]atmStrategyId[/B]);
                                      orderPlaced = true; atmCncEtry = false; atmClose = false;
                                  }
                                  else if(orderPlaced)
                                  {
                                              Print (Time[0].ToString("HH:mm:ss")+" NO state. Preparing to CANCEL ATM OrderID: "+orderId);
                                      CancelAllATM(orderId, atmStrategyId);
                                      orderPlaced = false;
                                  }
                      This is the Output Window showing the problem still exists.
                      OnBarUpdate: 06:35:21 Bar#: 3010 UP bar
                      06:35:21 LONG state. Preparing to CANCEL ATM OrderID: 086637701fc84606be4c1929fc6c9548
                      06:35:21 Inside CancelAllATM(). Gathering ATM status for orderID: 086637701fc84606be4c1929fc6c9548
                      06:35:21 Inside CancelAllATM(). Gathering ATM status for atmStrategyId: d4f6c3eedc30477ea8d5dc8544bec1c8
                      **NT** GetAtmStrategyStopTargetStatus() method error: OrderName 'TARGET1' does not exist
                      **NT** GetAtmStrategyStopTargetStatus() method error: OrderName 'STOP1' does not exist

                      06:35:21 CANCELING ATM Entry: 086637701fc84606be4c1929fc6c9548 State: PartFilled PartFilled = True
                      The current ATM Strategy market position is: Short
                      The current ATM Strategy position quantity is: 5
                      The current ATM Strategy average price is: 1260.2
                      The current ATM Strategy Unrealized PnL is: -49.9999999999545
                      06:35:21 CLOSING ATM: d4f6c3eedc30477ea8d5dc8544bec1c8 TARGET1 State: N/A STOP1 State: N/A
                      06:35:21 Leaving CancelAllATM() =================
                      06:35:21 GetAtmStrategyUniqueId() orderID: 98da24b826d74db78344a74f2fc960f2
                      06:35:21 GetAtmStrategyUniqueId() atmStrategyId: bdfca2fb3b744dc18cabff2388343d48
                      06:35:21 Placing Long Limit at: 1260 OrderID: 98da24b826d74db78344a74f2fc960f2 atmStrategyId: bdfca2fb3b744dc18cabff2388343d48
                      **NT** Submitting order with strategy 'ATMTest/7042fe1e3cb64fdeb214123cc15fb172'
                      **NT** AtmStrategyId parameter 'bdfca2fb3b744dc18cabff2388343d48' already used
                      What do you suggest next?
                      Thank you.
                      zacwhitesi
                      NinjaTrader Ecosystem Vendor - Shark Indicators

                      Comment


                        #12
                        Hello zacwhitesi,

                        Thank you for updating the code.

                        My tests are producing the same results as well. However, the only reason the results are occurring is because there is no Stop Loss or Profit Target submitted as the Entry was never filled. I have created a video on this item at the following, please review and let me know if this is the same item that you are seeing or not: http://screencast.com/t/fTnZJ4zt

                        Comment


                          #13
                          Hi Patrick,
                          Thanks for the video. I noticed you did not test the code during the specific date & time or instrument that I gave in my original post, that will recreate the issue every time. Also, you were discussing entries that did not have a partial fill. The debug prints to the Output Window I posted above is showing a partial fill of 5 Short contracts(that are highlighted in bold). I have attached screenshots with Chart Trader showing a Stop & Traget in place, but GetAtmStrategyStopTargetOrderStatus() is NOT recognizing them.
                          In conclusion, what you discussed in the video does not address this problem. Please review the original post again.
                          Thank you,
                          Zac[IMG]http://www.ninjatrader.com/support/forum/data:image/gif,GIF89a%12%00%12%00%B3%00%00%FF%FF%FF%F7%F7%EF% CC%CC%CC%BD%BE%BD%99%99%99ZYZRUR%00%00%00%FE%01%02 %00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%0 0%00%00%00%00!%F9%04%04%14%00%FF%00%2C%00%00%00%00 %12%00%12%00%00%04X0%C8I%2B%1D8%EB%3D%E4%00%60(%8A %85%17%0AG*%8C%40%19%7C%00J%08%C4%B1%92%26z%C76%FE %02%07%C2%89v%F0%7Dz%C3b%C8u%14%82V5%23o%A7%13%19L %BCY-%25%7D%A6l%DF%D0%F5%C7%02%85%5B%D82%90%CBT%87%D8i7 %88Y%A8%DB%EFx%8B%DE%12%01%00%3B[/IMG]
                          Attached Files
                          Last edited by zacwhitesi; 02-27-2014, 02:41 PM.
                          zacwhitesi
                          NinjaTrader Ecosystem Vendor - Shark Indicators

                          Comment


                            #14
                            Hello zacwhitesi,

                            Thank you for your patience.

                            Not sure what is different about my AtmTest strategy and yours, but please refer to the attached screenshot where you can see my Output clearly shows the status of the orders during a partial fill. I have also attached my AtmTest for reference.
                            Attached Files

                            Comment


                              #15
                              Hi Patrick,
                              Your screenshot shows a trade time at 06:34:44 were the issue does not occur. Again, I specifically stated the time at which the problem occurres. I'm starting to think you are avoiding the issue by not testing the exact setup I gave above. I made a video using your attached strategy, and it shows the problem as stated in my first post.
                              World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.


                              Thank you.
                              zacwhitesi
                              NinjaTrader Ecosystem Vendor - Shark Indicators

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              647 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              368 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
                              571 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              573 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X