Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unexpected "close Position" in Control Center trade log

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

    Unexpected "close Position" in Control Center trade log

    I am developing a new strategy and am seeing an unexpected "Close Position" in the Control Center Execution log. The attached picture captures the salient events.
    The strategy code is written so that it can enter a trade ONLY iff it is not in a trade. The code to evaluate the condition(s) to exit a position is executed before the code to evaluate a possible enter of a position. The strategy may exit a position in one direction AND enter a position in the opposite direction on the same bar.
    The case in point (attached picture) shows an output window trace-- trace order plus my own annotations and a section of the execution log for the transaction. In the highlighted section of the output window the code evaluates and exits a previously established long position. This is recorded, as expected, in the execution log - the first entry at 10:47:53. Subsequently, the strategy enters a short position - as recorded by the THIRD 10:47:53 entry. What is UNEXPECTED in the second entry in the execution log - the "Close Position 2" entry.
    Apparently there is a problem with the way I have coded this... but I have exhausted all ideas. Please Help!
    Attached Files

    #2
    Hello ts_gordo,

    Thank you for your post.

    It appears that an Enter() method is being submitted while you are in the opposite position, such as you are long and an EnterShort() is submitted before the Long position is closed. This is causing an overfill.

    You state the you are processing the exit of the position in OnBarUpdate() before the entries are checked and processed. However, this would be all on the same bar. So we would see an Exit submitted followed by an Enter that would submit a Close Position order even though the Exit has been sent.

    Unfortunately, we can not avoid the Enter methods submitting a Close Position order if they see an open position. While your code in OnBarUpdate() processes Exit condition first and then Enter conditions, the position update has not been called yet.

    With all the above aside, you also mentioned that you ensure your position is closed before sending new entries. Can you provide a snippet of code used to do this?

    Comment


      #3
      Thank you, Patrick
      I think you have identified my problem. My confusion, if I have understood your comments correctly, is in assuming that issuing the "exit" was sufficient to close out the position.. I did not mean to imply in my original post that the code was actually "waiting" for the order to fill... something I will now add.
      I'll keep you posted.

      Thanks again

      Comment


        #4
        Since original exchange I have tried several approaches to force the code to wait, after issuing the "exit" order, for the order to fill before advancing, in case there will be a subsequent "entry" order. Approaches tried include using IOrder to check the order status and IExecution to asynchronously set a completion flag. Nothing tried has succeeded and most attempts have resulted in hanging NT - I assume because the status being tested never occurs - making debugging difficult.

        Can someone suggest a way to verify that an order has executed?

        Comment


          #5
          Hello,

          Thank you for the question.

          Since original exchange I have tried several approaches to force the code to wait, after issuing the "exit" order, for the order to fill before advancing, in case there will be a subsequent "entry" order. Approaches tried include using IOrder to check the order status and IExecution to asynchronously set a completion flag. Nothing tried has succeeded and most attempts have resulted in hanging NT - I assume because the status being tested never occurs - making debugging difficult.
          I wanted to ask, it sounds like you have used OnExectuion based on the IExecution being listed, is this correct? If so this would have been what I would recommend to check for a filled order. You said the status being tested never occurs, which status are you trying to capture? If you are trying to check for Filled, OnExecution would show this and it may be the way it is being checked causing the issue.

          OnExecution will show filled executions, if you are looking for a state like Working, you would need to use OnOrderUpdate instead.

          Can you provide more details on the status you are trying to get?

          I look forward to being of further assistance.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          633 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          364 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          105 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          567 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          568 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X