Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

cancel an atm strategy limit order

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

    cancel an atm strategy limit order

    I am having problems with cancelling and atm strategy limit order. When it is time to place the limit order, this is my code for it:
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, limitLevel, 0,
    TimeInForce.Gtc, GetAtmStrategyUniqueId(), atmName,
    orderId);
    limitCloseBars = CurrentBars[1] + unfilledBars;
    then after x amount of bars if the order isn't filled, I try to close it using this code:
    if(CurrentBars[1] >= limitCloseBars)
    {
    closeEntry =
    true;
    }
    if(closeEntry == true)
    {
    // string[] entryInfo = GetAtmStrategyEntryOrderStatus(orderId);
    // if(entryInfo.Length > 0 && entryInfo[2] != "Filled")
    // {
    AtmStrategyCancelEntryOrder(orderId);
    // }
    closeEntry = false;
    }
    if i delete the // then AtmStrategyCancelEntryOrder(orderId); is never called. Even with the code like this my order isn't cancelled. I even put
    AtmStrategyCancelEntryOrder(orderId); as the first line of code under OnBarUpdate and it still would not cancel the order. What am I doing wrong?

    #2
    laces2, if the AtmStrategyCancelEntryOrder() method isn't called, that means the conditions for the method to be called are not being met. Is the entryInfo.Length longer than zero, and you're sure the order hasn't been filled?
    AustinNinjaTrader Customer Service

    Comment


      #3
      That is why I have it commented out. To make sure that it was being called I had it draw dots on the chart. I even at one point put the
      AtmStrategyCancelEntryOrder(orderId); as the very first thing in my strategy to make sure that it was called and still nothing. I know the order wasn't filled because I could see it on another chart, and it was in the working state in the control panel. The only time orderId is changed is right before a new order or trade is placed so I know that I am trying to cancel the right order. I am going to try to make a simple strategy today to see if I can get it to work.

      Comment


        #4
        Hello laces2,

        You'll want to work from the SampleAtmStrategy. You can save a copy by right clicking > Save As from within the editor. Cancelling an entry order would take place in this block:
        Code:
        // Check for a pending entry order
        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
        
        if (status.GetLength(0) > 0)
        {
        // Print out some information about the order to the output window
        
        [COLOR="Blue"]if(closeEntry == true)
        {
        AtmStrategyCancelEntryOrder(orderId);
        closeEntry = false;
        }[/COLOR]
        
        Print("The entry order average fill price is: " + status[0]);
        Print("The entry order filled amount is: " + status[1]);
        Print("The entry order order state is: " + status[2]);
        
        // If the order state is terminal, reset the order id value
        if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
        orderId = string.Empty;
        }
        Ryan M.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by DJ888, 04-16-2024, 06:09 PM
        3 responses
        10 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by RookieTrader, Today, 07:41 AM
        0 responses
        1 view
        0 likes
        Last Post RookieTrader  
        Started by maybeimnotrader, Yesterday, 05:46 PM
        1 response
        18 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Perr0Grande, Yesterday, 08:16 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by f.saeidi, Yesterday, 08:12 AM
        3 responses
        25 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X