Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Partially filled order processing issue

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

    Partially filled order processing issue

    Hello NT8 support.
    Let me tell you about rare issue that I experience periodically in my strategy.
    Since I want all orders to be under the total control of the strategy logic, I use Unmanaged approach.
    Also I use logging both custom and native one. So I can see the detailed workflow of the strategy.
    I also use Interactive Broker as market data provider. By the way, the majority of my problems in NT8 is related to IB for some reason...
    The key strategy logic has the following structure.

    Code:
    protected override void OnOrderTrace(DateTime timestamp, string message)
    {
        // Log #1
    }​
    
    protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)​
    {
        // Log #2
    }
    
    protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, int quantity, Cbi.MarketPosition marketPosition)
    {
        // Log #3
        if (marketPosition == MarketPosition.Flat)
        {
            // Some logic #2
        }
        else
        {
            // Some logic #3
        }
    }
    
    protected override void OnBarUpdate()
    {
        // Some logic #1
    }
    Let's consider a piece of the trading logic where we have active position of 100 contracts size and some exit condition is triggered that flattens the position.
    In the most cases the logging system outputs the following:

    Log #1 (exit order submission);
    Log #2 (exit order states from Working to Filled);
    Log #3 (position is Flat, size = 0 contracts);
    "Some logic #2" is executed.

    This way my strategy works for days and even weeks. But sometimes unexpected thing happens... I mean "partially filled" state of exit order. When it happens I see the following output.

    Log #1 (exit order submission);
    Log #2 (exit order states from Working to Partially Filled with filled quantity 50);
    Log #3 (position is still Long (or Short), size = 50 contracts);
    Log #2 (exit order state Filled);

    ...​ and that is all! Logically, another Log #3 (another call of OnPositionUpdate callback) is expected. But no such an action, no "Some logic #2" execution, trading logic is broken... But NT8 native log shows the removed position.

    Is there any suggestion of how to process partially filled orders so that the strategy gets the signal that the position is Flat? Thank you.
    Last edited by PopovDS; 05-27-2024, 07:13 AM.

    #2
    Hello PopovDS,

    I would expect after the order finishes part filling and is fully filled that the position would update with OnPositionUpdate(), though with Interactive Brokers and Rithmic connections this can occur out of sequence.

    May I confirm you are using 8.1.3.0?

    If so, we may be looking at the brokerage not sending the last position update message to NinjaTrader.

    May I have you send an email to scriptingsupport[at]ninjatrader.com with a link to the forum thread. I'd like to request your log and trace files to see if this is the case.


    That said, you can track the position quantity from the executions. The example linked below includes sample logic that does this.
    Hello, I see in the documentation you have fixed: 15048 Added Adapter, Rithmic Updated Rithmic API to version 11.3.0.0 Can you elaborate on that please? Will OnOrderUpdate() OnExecutionUpdate() and OnPositionUpdate() be called in the expected order?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea B.
      Thank you for response. For some reasons I refrained from updating and my current version of NT8 is 8.1.2.1.

      Comment


        #4
        Hello PopovDS,

        Please update to the latest release and retest for the behavior.


        If the behavior still occurs with the latest release, please send in an email so I can review the log and trace files.
        Chelsea B.NinjaTrader Customer Service

        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
        133 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