Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Questions OnExecutionUpdate

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

    Questions OnExecutionUpdate

    Hello,

    I have reviewed the SampleOnOrderUpdate code and I have some questions regarding the OnExecutionUpdate here:
    Code:
     [COLOR=#0000ff]protected[/COLOR] [COLOR=#0000ff]override[/COLOR] [COLOR=#0000ff]void[/COLOR] [COLOR=#080808]OnExecutionUpdate[/COLOR]([COLOR=#080808]Execution[/COLOR] [COLOR=#080808]execution[/COLOR], [COLOR=#0000ff]string[/COLOR] [COLOR=#080808]executionId[/COLOR], [COLOR=#0000ff]double[/COLOR] [COLOR=#080808]price[/COLOR], [COLOR=#0000ff]int[/COLOR] [COLOR=#080808]quantity[/COLOR], [COLOR=#080808]MarketPosition[/COLOR] [COLOR=#080808]marketPosition[/COLOR], [COLOR=#0000ff]string[/COLOR] [COLOR=#080808]orderId[/COLOR], [COLOR=#080808]DateTime[/COLOR] [COLOR=#080808]time[/COLOR])
     {
     [COLOR=#006400]/* We advise monitoring OnExecution to trigger submission of stop/target orders instead of OnOrderUpdate() since OnExecution() is called after OnOrderUpdate()
     which ensures your strategy has received the execution which is used for internal signal tracking. */
    [/COLOR][COLOR=#0000ff]if[/COLOR] ([COLOR=#080808]entryOrder[/COLOR] != [COLOR=#0000ff]null[/COLOR] && [COLOR=#080808]entryOrder[/COLOR] == [COLOR=#080808]execution[/COLOR].[COLOR=#080808]Order[/COLOR])
     {
     [COLOR=#0000ff]if[/COLOR] ([COLOR=#080808]execution[/COLOR].[COLOR=#080808]Order[/COLOR].[COLOR=#080808]OrderState[/COLOR] == [COLOR=#080808]OrderState[/COLOR].[COLOR=#080808]Filled[/COLOR] || [COLOR=#080808]execution[/COLOR].[COLOR=#080808]Order[/COLOR].[COLOR=#080808]OrderState[/COLOR] == [COLOR=#080808]OrderState[/COLOR].[COLOR=#080808]PartFilled[/COLOR] || ([COLOR=#080808]execution[/COLOR].[COLOR=#080808]Order[/COLOR].[COLOR=#080808]OrderState[/COLOR] == [COLOR=#080808]OrderState[/COLOR].[COLOR=#080808]Cancelled[/COLOR] && [COLOR=#080808]execution[/COLOR].[COLOR=#080808]Order[/COLOR].[COLOR=#080808]Filled[/COLOR] > [COLOR=#ff8c00]0[/COLOR]))
     {
     [COLOR=#006400]// Stop-Loss order 4 ticks below our entry price
    [/COLOR][COLOR=#080808]stopOrder[/COLOR] = [COLOR=#080808]ExitLongStopMarket[/COLOR]([COLOR=#ff8c00]0[/COLOR], [COLOR=#0000ff]true[/COLOR], [COLOR=#080808]execution[/COLOR].[COLOR=#080808]Order[/COLOR].[COLOR=#080808]Filled[/COLOR], [COLOR=#080808]execution[/COLOR].[COLOR=#080808]Order[/COLOR].[COLOR=#080808]AverageFillPrice[/COLOR] - [COLOR=#ff8c00]4[/COLOR] * [COLOR=#080808]TickSize[/COLOR], [COLOR=#b22222]"MyStop"[/COLOR], [COLOR=#b22222]"MyEntry"[/COLOR]);
     [COLOR=#006400]// Target order 8 ticks above our entry price
    [/COLOR][COLOR=#080808]targetOrder[/COLOR] = [COLOR=#080808]ExitLongLimit[/COLOR]([COLOR=#ff8c00]0[/COLOR], [COLOR=#0000ff]true[/COLOR], [COLOR=#080808]execution[/COLOR].[COLOR=#080808]Order[/COLOR].[COLOR=#080808]Filled[/COLOR], [COLOR=#080808]execution[/COLOR].[COLOR=#080808]Order[/COLOR].[COLOR=#080808]AverageFillPrice[/COLOR] + [COLOR=#ff8c00]8[/COLOR] * [COLOR=#080808]TickSize[/COLOR], [COLOR=#b22222]"MyTarget"[/COLOR], [COLOR=#b22222]"MyEntry"[/COLOR]);
     [COLOR=#006400]// Resets the entryOrder object to null after the order has been filled
    [/COLOR][COLOR=#0000ff]if[/COLOR] ([COLOR=#080808]execution[/COLOR].[COLOR=#080808]Order[/COLOR].[COLOR=#080808]OrderState[/COLOR] != [COLOR=#080808]OrderState[/COLOR].[COLOR=#080808]PartFilled[/COLOR])
     {
     [COLOR=#080808]entryOrder[/COLOR] = [COLOR=#0000ff]null[/COLOR];
     }
     }
     }
     [COLOR=#006400]// Reset our stop order and target orders' Order objects after our position is closed.
    [/COLOR][COLOR=#0000ff]if[/COLOR] (([COLOR=#080808]stopOrder[/COLOR] != [COLOR=#0000ff]null[/COLOR] && [COLOR=#080808]stopOrder[/COLOR] == [COLOR=#080808]execution[/COLOR].[COLOR=#080808]Order[/COLOR]) || ([COLOR=#080808]targetOrder[/COLOR] != [COLOR=#0000ff]null[/COLOR] && [COLOR=#080808]targetOrder[/COLOR] == [COLOR=#080808]execution[/COLOR].[COLOR=#080808]Order[/COLOR]))
     {
     [COLOR=#0000ff]if[/COLOR] ([COLOR=#080808]execution[/COLOR].[COLOR=#080808]Order[/COLOR].[COLOR=#080808]OrderState[/COLOR] == [COLOR=#080808]OrderState[/COLOR].[COLOR=#080808]Filled[/COLOR] || [COLOR=#080808]execution[/COLOR].[COLOR=#080808]Order[/COLOR].[COLOR=#080808]OrderState[/COLOR] == [COLOR=#080808]OrderState[/COLOR].[COLOR=#080808]PartFilled[/COLOR])
     {
     [COLOR=#080808]stopOrder[/COLOR] = [COLOR=#0000ff]null[/COLOR];
     [COLOR=#080808]targetOrder[/COLOR] = [COLOR=#0000ff]null[/COLOR];
     }
     }
     }
    For the entryOrder an ExitLongStopMarket order is placed when either the entryOrder is "Filled" or "PartFilled". My question is if the stopOrder order ID is the same if PartFilled occurs?

    Let's say there are two partial orders to fill complete order. The ExitLongStopMarket order uses the same "MyEntry" entry signal name. When the two stop orders are replaced do we get the same stop order id ?

    2nd question is about the process of resetting the stopOrder and targetOrder to null when the stop and target orders are either Filled OR PartFilled. Is this an error? Shouldn't we only reset the stopOrder and targetOrder only when the stopOrder or targetOrder objects are completely Filled?

    Thanks

    #2
    Hello tornadoatc,

    When an order part fills, the OrderId of the order remains the same on each part fill of the same order.

    The execution.ExecutionId will different for each part fill execution.

    However, if you have two different orders that are submitted separately, these will have different OrderIds.


    Regarding the SampleOnOrderUpdate, I agree that this should not reset the IOrders for the stop and target after a part fill.
    I have submitted a request to have this changed in your behalf.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X