Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AtmStrategyChangeEntryOrder()

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

    AtmStrategyChangeEntryOrder()

    Hi,I am having trouble with canceling entry orders, the code below is submitting an entry order at each close after the first trade.


    I am using the AtmStrategyChangeEntryOrder() so that if i miss an entry, the entry order will be submitted on the next bar's closing price. But once a trade is filled i want it to cancel changing my entry order, any suggestions on how i can cancel
    AtmStrategyChangeEntryOrder() once an order is filled?

    Code:
    if(LongSetUp == true
                    &&     orderId.Length == 0 && atmStrategyId.Length == 0)
                    {
                        atmStrategyId = GetAtmStrategyUniqueId();
                        orderId = GetAtmStrategyUniqueId();
                        AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, Close[0], 0, TimeInForce.Gtc, orderId, "NQ",atmStrategyId);
                        AtmStrategyChangeEntryOrder(Close[0], 0, orderId);
                        //How to stop this from submitting an order after each close
                        //reset the longsetup once filled or keep chasing it
                            if (orderId.Length > 0)
                            {                
                                string[] status = GetAtmStrategyEntryOrderStatus(orderId);
                                // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
                                // Check length to ensure that returned array holds order information
                            if (status.GetLength(0) > 0)
                            {
                                
                                // If the order state is terminal, reset the order id value
                                if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
                                {
                                LongSetUp = false;
                                AtmStrategyCancelEntryOrder(orderId);
                                
                                }
                            }
                            //reset it once order is "FILLED" not submitted
                            }
                    }

    #2
    Hello dawdler,

    Once the entry order has been placed, orderId.Length should be a non zero value. You may get better results placing it in the block indicated below, and you will also have to define your condition for
    so that if i miss an entry, the entry order will be submitted on the next bar's closing price.
    // Check for a pending entry order
    if (orderId.Length > 0)
    {
    AtmStrategyChangeEntryOrder(Close[0], 0, orderId);
    string[] status = GetAtmStrategyEntryOrderStatus(orderId);
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your help Ryan. I placed AtmStrategyChangeEntryOrder() where u suggested, but i don't seem to be needing an condition for handling a missed entry, the code is automatically adjusting my entry order to next bar's close.Thanks again!

      Below is the corrected code for reference

      Code:
      if (orderId.Length > 0)
                  {
                      string[] status = GetAtmStrategyEntryOrderStatus(orderId);
                      AtmStrategyChangeEntryOrder(Close[0], 0, orderId);    
                      
                      if (status.GetLength(0) > 0)
                      {
                        
                          if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
                              orderId = string.Empty;
                              ShortSetUp = false;
                              LongSetUp = false;
                      }

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      61 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      149 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      162 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      99 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      286 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X