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 sjsj2732, Today, 04:31 AM
            0 responses
            20 views
            0 likes
            Last Post sjsj2732  
            Started by NullPointStrategies, 03-13-2026, 05:17 AM
            0 responses
            280 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            279 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            130 views
            1 like
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            90 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Working...
            X