Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to know when a trade has closed in an automated ATM strategies

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

    how to know when a trade has closed in an automated ATM strategies

    I am writing a NinjaScript automation strategy using the ATM functions to call my ATM setup.

    in my ATM setup I have 1 profit exit, and 1 stop loss exit. I need to somehow know when an entry trade has exited (ie trade closed) so that I can let the strategy set up the next trade.

    I was thinking about using GetAtmStrategyStopTargetOrderStatus(), however according to the documentation, it would be hard to tell from this function whether the trade is 100% closed or partially closed, depending on the fill of the stop loss/target.

    Can someone explain how to tell when an trade has closed 100% through the ATM functions ? Or is there another set of functions I should use ?

    #2
    Hello,

    I will have someone reply to you on Monday. Thank you for your patience.
    DenNinjaTrader Customer Service

    Comment


      #3
      thanks, I can hold for an answer, btw, there's what I wrote

      just want to add the function I wrote that I believe will tell me if an atm automated strategy that has filled (I enter trades with a stop order) has either fully hit the profit target (limit order) or stop loss (stop order) :

      (as a side note, my atm strategy enters a trade with 1 stop order, and exits with either 1 limit order(profit target) or 1 stop order (stop loss). No scaling in/out happens.

      protected bool IsOrderClosed(string id)
      {
      Print ("\tChecking for closed order with atmID = " + id);
      string[,] orders = GetAtmStrategyStopTargetOrderStatus("TARGET1", id);
      // 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\tOrder id(" + id + " : 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(id);
      if (!success) Print ("\t\t\tfailed to find AtmOrderId: " + id + " when attempting to close");
      return true;
      }
      }

      // now check for a stop loss fill
      string[,] orders2 = GetAtmStrategyStopTargetOrderStatus("STOP1", id);
      // 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 = " + id + " has not closed");
      return false;
      }
      }

      Comment


        #4
        pepelucho, I think you could combine the GetAtmStrategyStopTargetOrderStatus() with for comparing fill quantities and overall market position of the called ATM - http://www.ninjatrader-support.com/H...yPosition.html

        If you haven't checked into already, the SampleAtmStrategy installed per default shows those methods at work.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        666 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        377 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        110 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        575 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        580 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X