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 CarlTrading, 03-31-2026, 09:41 PM
            1 response
            128 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            73 views
            1 like
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            116 views
            2 likes
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            109 views
            1 like
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            88 views
            0 likes
            Last Post CarlTrading  
            Working...
            X