Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 algospoke, Yesterday, 06:40 PM
    2 responses
    19 views
    0 likes
    Last Post algospoke  
    Started by ghoul, Today, 06:02 PM
    3 responses
    14 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by jeronymite, 04-12-2024, 04:26 PM
    3 responses
    45 views
    0 likes
    Last Post jeronymite  
    Started by Barry Milan, Yesterday, 10:35 PM
    7 responses
    20 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by AttiM, 02-14-2024, 05:20 PM
    10 responses
    181 views
    0 likes
    Last Post jeronymite  
    Working...
    X