Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

A position size issue

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

    A position size issue

    Hello NT8 support.
    In rare occasions I face the issue of missed OnPositionUpdate event what entails wrong further trading logic. Let me explain step by step.
    The 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 OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
       // Log #3
    }​
    
    protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, int quantity, Cbi.MarketPosition marketPosition)
    {
        // Log #4
        if (quantity == 3)
        {
            // Some logic #2
        }
    }
    
    protected override void OnBarUpdate()
    {
        // Some logic #1
    }​
    I use logging to see the logic workflow.
    Let's suppose entry condition is met and the logic places 2 orders consecutively:
    1. Entry for TP1 2 contracts.
    2. Entry for TP2 1 contract.

    In the most cases I see normal workflow in the log. I see 2 placed and filled orders. As result I have an opened position of size 3 and "Some logic #2" is executed. But in rare occasions I see the following sequence:

    1. Log #1 shows entry for TP1 has been placed (2 contracts)
    2. Log #1 shows entry for TP2 has been placed (1 contracts)
    3. Log #3 shows execution for TP1 has been processed (1 contracts)
    4. Log #2 shows order for TP1 has been filled (2 contracts)
    5. Log #3 shows execution for TP1 has been filled (1 contract)
    6. Log #2 shows order for TP2 has been filled (1 contract)
    7. Log #4 shows the position has changed (quantity 2)
    8. Log #3 shows execution for TP2 has been filled (1 contract)

    And no any log records any more... The logic can't follow "Some logic #2" until the position size is 2. it waits for 3. But it seems OnPositionUpdate call was missed...

    I posted something similar here https://forum.ninjatrader.com/forum/...ocessing-issue. I used IB connection that time. Now I use Continuum as market provider and the latest version of NT8 (8.1.3.0). Do you also experience any problems of position size calculation with Continuum?

    #2
    Hello PopovDS,

    Is your broker NinjaTrader Brokerage or do you use a different brokerage?

    If the brokerage is NinjaTrader Brokerage, please try creating the connection as the NinjaTrader type based on Tradovate instead of Continuum and see if you are able to reproduce the behavior.

    Interactive Brokers is known to send execution, order, and instrument position updates out of sequence.
    Below is a link to a forum thread discussing this.


    This was not known to be an issue for Continuum connections.

    Can you provide an export of a reduced test script with only the minimum code necessary to reproduce and the output saved from the ninjascript output window for us to examine?
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    59 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
    50 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X