Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by skorpn, Today, 01:28 AM
        0 responses
        2 views
        0 likes
        Last Post skorpn
        by skorpn
         
        Started by ETFVoyageur, Today, 12:52 AM
        0 responses
        6 views
        0 likes
        Last Post ETFVoyageur  
        Started by Board game geek, Yesterday, 02:20 AM
        2 responses
        21 views
        0 likes
        Last Post Board game geek  
        Started by jackiegils, Yesterday, 11:05 PM
        0 responses
        6 views
        0 likes
        Last Post jackiegils  
        Started by cre8able, 05-09-2024, 09:15 PM
        2 responses
        17 views
        0 likes
        Last Post cre8able  
        Working...
        X