Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to tell when a position goes to 0 (i.e. is closed)

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

    how to tell when a position goes to 0 (i.e. is closed)

    For Rithmic, when I receive an Order in OnOrderUpdate with Name = "Close" I know the position has been Flattened

    but how do I tell when a position is vacated by opposing orders?

    Entry Order: Buy Limit 1 contract

    Exit Order Sell Market 1 contract

    Thanks


    #2
    for connection Rithmic

    Comment


      #3
      I noticed that the Position collection does not give accurate counts (for Rithmic)...was told that some brokers don't update this info in real time very well...so...chatgpt suggested I use OnExecution like this

      what do you think?

      ---------------------------------------------------------------------------------------------------------------------------------

      private int lastPosition = 0; // Track the last position size

      protected override void OnExecution(ExecutionEventArgs e)
      {
      // Check the current position after each execution event
      int currentPosition = Position.Quantity;

      // Check if the position has been vacated
      if (currentPosition == 0 && lastPosition != 0)
      {
      Print("Position has been vacated (closed).");
      }

      // Update last position size
      lastPosition = currentPosition;
      }

      Comment


        #4
        I need to do this in an Indicator, not a Strategy

        Comment


          #5
          Hello,

          Thank you for your post.

          The recommended way to track positions on an account is using Account.Positions.



          If you want to build your own custom logic to track positions, you could do so at your own discretion.

          Comment


            #6
            ok, but Positions is not working for Rithmic...tested it, and had a message I think in the forum that not all brokers provide accurate Position into

            though, I do believe that when a position is closed it is deleted from the Position collection....but am unsure of the timing...I am working at the tick level

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            557 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            324 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            545 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            547 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X