I have reviewed the SampleOnOrderUpdate code and I have some questions regarding the OnExecutionUpdate here:
[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]; } } }
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
Comment