Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cancel order loop logic not cancelling entry orders.

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

    #16
    Hello elliot5,

    For the new error I can't tell what line that may be, you can undo the changes to get rid of that.

    This part of your condition uses a specific order variable that you made:
    Code:
    && myEntryOrderESSHORT != null)
    The loop you have made is covering a list of multiple orders.
    Code:
    foreach(Order order in orderList)
    the orders in the list may or may not be ES SHORT LIMIT1, I can't tell from this small of a sample what you are adding to the list.

    The error you are getting simply means something was null and if the line which throws the error is if( order.Name == "ES SHORT LIMIT" + esuhsc) that means the order in your list was null. I can't say what order that was because it was null so we cant get the name of it.

    To bypass that order because its null you could use a null check

    Code:
    if(order != null)
    {
        // order exists and is not null
    }
    I look forward to being of further assistance.

    Comment


      #17
      ok great explanation but where do I place that null check? and that order list - it needs to be regularly cleared yes? Otherwise old legacy orders will clearly be null for new executions sets. Is it possible to print to output the orderList?
      Last edited by elliot5; 03-16-2021, 10:46 AM.

      Comment


        #18
        Hello elliot5,

        That would need to surround where you used the order variable inside of the foreach . If the order object is null the null check has to go around that line.

        The list would not need cleared, you would need to manage what is in the list from the order events based on the events being observed. For example if an order was cancelled you would need to check the name of the cancelled order, then find it in the list, then remove it from the list.

        You can use prints on order objects in the list so you could put a print in the loop. The same problem applies though if the order object is null the print would not work on that object. You could use the print within the null check to print the details of non null objects. If you are seeing null objects in the list it sounds like the other logic in the OnOrderUpdate or OnExecutionUpdate is not removing the items.

        I look forward to being of further assistance.

        Comment


          #19
          Excellent service. Thank you Jesse - you are what makes NT such a great product. Thank you

          Comment


            #20
            I have sorted out the error messages but am unable to get a cancel using:

            if( order.Name == "ES SHORT LIMIT" + esuhsc)
            CancelOrder(order);

            In an older version of the code without the loops using CancelOrder(myEntryOrder) always worked. Why am I not able to access and cancel the order via order.Name? Is that only accessible via OnOrderUpdate perhaps. Regards
            Last edited by elliot5; 04-13-2021, 01:16 PM.

            Comment


              #21
              Hello elliot5,

              The CancelOrder method requires an order object to cancel it.

              Have you tried to Print the orders you are looping over to check if the order in question is actually in the list?

              Are you otherwise seeing any output in the output window or log when trying to cancel the order?

              Code:
              foreach(Order order in orderList)
              {
                  if(order != null)
                  {
                       Print(order.Name);
                  }
              }

              I look forward to being of further assistance.

              Comment


                #22
                Will do that print check and report back.

                Comment


                  #23
                  I was able to print the list and get the cancel to work. The problem was that I have another code section that was clearing the list periodically - hence the list was empty upon testing. Do I need to clear the list on a regular basis in your opinion? Regards and many thanks

                  Comment


                    #24
                    Hello elliot5,

                    You very unlikely would want to clear the whole list. You need to use the order events like Filled or Cancelled from OnOrderUpdate and OnExecutionUpdate to Remove specific elements from the list when they are finished. Your list will have the .Remove method which can be used.

                    If you just clear the list that will leave you in the situation you are currently in where some logic may not work because the order is now missing from the list.


                    I look forward to being of further assistance.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Yesterday, 05:17 AM
                    0 responses
                    56 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    132 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    73 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    45 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    49 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X