Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issue with SL and TP orders not matching between computer and servcer

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

    Issue with SL and TP orders not matching between computer and servcer

    I've noticed on days when my strategy fills my position with partial orders, that while my exit orders on my local marching running the strategy show the full position size, the orders on the server only match is initial partial order fill.

    On Tuesday, I had a position of 9 MES contracts. My local machine showed my TP and SL order as 9, but the server showed only 2. The entry was filled like this: 2, 1, 1, 1, 1, 1, 1, 1. The result was when target was hit, only 2 MES contracts were sold, the rest I had to manage my manually selling at market. (Even the "Flatten Everything" function didn't work).

    Today, a similar incident happened. I sold 7 MES contracts and my position was filled in the following manner: 1, 2, 1, 1, 2. The machine running the strategy showed orders for 7 contracts on the TP and SL exits. Yet, when I opened the trade up on another machine it showed only 1 contract for the TP and SL. In this case, I updated the TP and SL quantities in the Orders tap of the Command Center, but I really want to squash this bug in my code so I won't have to.

    The logic seems ok to me, but obviously I'm missing something. I'm posting the entire section for order execution. Let me know if I can clarify anything for you:

    Code:
    if (myMicroEntryOrder != null && myMicroEntryOrder == execution.Order)
    {
    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
    {
    // Sum the quantities of each executio making up the entry order
    sumPrimeMicroFilled += execution.Quantity;
    
    //Submit exit orders for partial fills
    if (execution.Order.OrderState == OrderState.PartFilled)
    {
    if (direction == "LONG")
    {
    microStopOrder = ExitLongStopMarket(microTradeDataSeries, true, execution.Order.Filled,PrimeStp1Price, "PrimeMicroLongStop", "MicroEntryLong");
    microProfitOrder = ExitLongLimit(microTradeDataSeries, true, execution.Order.Filled,PrimeTargetPrice, "PrimeMicroLongTarget" , "MicroEntryLong");
    }
    if (direction == "SHORT")
    {
    microStopOrder = ExitShortStopMarket(microTradeDataSeries, true, execution.Order.Filled, PrimeStp1Price, "PrimeMicroShortStop" , "MicroEntryShort" );
    microProfitOrder = ExitShortLimit(microTradeDataSeries, true, execution.Order.Filled, PrimeTargetPrice, "PrimeMicroShortTarget" , "MicroEntryShort");
    }
    Print(String.Format("Part Filled: {0}",sumPrimeMicroFilled));
    }
    //Update our exit order quantities once orderstate turns to filled and we have seen execution quantities match order quantities
    else if (execution.Order.OrderState == OrderState.Filled && sumPrimeMicroFilled == execution.Order.Filled)
    {
    if (direction == "LONG")
    {
    microStopOrder = ExitLongStopMarket(microTradeDataSeries, true, execution.Order.Filled, PrimeStp1Price, "PrimeMicroLongStop", "MicroEntryLong" );
    microProfitOrder = ExitLongLimit(microTradeDataSeries, true, execution.Order.Filled, PrimeTargetPrice, "PrimeMicroLongTarget", "MicroEntryLong" );
    }
    if (direction == "SHORT")
    {
    microStopOrder = ExitShortStopMarket(microTradeDataSeries, true, execution.Order.Filled, PrimeStp1Price, "PrimeMicroShortStop", "MicroEntryShort" );
    microProfitOrder = ExitShortLimit(microTradeDataSeries, true, execution.Order.Filled, PrimeTargetPrice, "PrimeMicroShortTarget", "MicroEntryShort" );
    
    }
    Print(String.Format("Complete Filled: {0}",sumPrimeMicroFilled));
    
    }
    //Reset the entry order and sum counter to null / 0 after the order has been filled
    if (execution.Order.OrderState != OrderState.PartFilled && sumPrimeMicroFilled == execution.Order.Filled)
    {
    myMicroEntryOrder = null;
    sumPrimeMicroFilled = 0;
    }
    }
    } //end myMicroEntryOrder​
    
    if ((microStopOrder != null && microStopOrder == execution.Order) || (microProfitOrder != null && microProfitOrder == execution.Order))
    {
    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
    {
    microStopOrder = null;
    microProfitOrder = null;
    Print("Micro Profit and Stop orders are nulled");
    }
    
    }
    Thank you for any help, I have a manual work around, but would really like to understand my error in understanding this logic.​

    #2
    Hello maltin,

    Thanks for your post.

    I do not see anything specific standing out in the code you shared.

    What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.0.?.?)​

    Who is your broker?

    Do you receive an error on screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?

    When you mention "on my local marching running the strategy show the full position size, the orders on the server only match is initial partial order fill." how exactly are you comparing this? Are you comparing the Position tab on the Strategies tab of the Control Center to the Accounts tab of the Control Center?

    Are you able to reproduce the behavior using the SampleOnOrderUpdate() reference sample from the help guide?

    SampleOnOrderUpdate(): https://ninjatrader.com/support/help...and_onexec.htm

    We look forward to assisting further.

    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    55 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    132 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