I changed all the order submission in my strategy to unmanaged order and I have the following problem:
When I have an order and it is partially filled, example the one below where the order is for 5 contracts, first I buy 1 and then I buy 4, 2 Take Profit Orders and 2 Stop Loss Orders are generated, 1 for each filled order.
Now when my system goes into Trail Stop mode, I need to cancel the Oco Created orders, but it only cancels the last one that has been filled.
I need cancel all OCO orders in this case the 2 OCO Orders that were Created.
Entry Order
Datos de la Orden de Entrada LE orderId='06b7a0f03c3e4e0aa5b0b7eeefa7d38f' account='Playback101' name='LE' orderState=Accepted instrument='NQ 09-20' orderAction=Buy orderType='Stop Market' limitPrice=0 stopPrice=10381 quantity=5 tif=Gtc oco='unmanagedentryoco1033086642' filled=0 averageFillPrice=0 onBehalfOf='' id=37261 time='2020-07-02 09:15:01' gtd='2099-12-01' statementDate='2020-07-02'
1 Filled
Datos de La Orden Take Profit LE orderId='86bc94413acc450b95e26167f20f11e1' account='Playback101' name='longProfitTarget' orderState=Working instrument='NQ 09-20' orderAction=Sell orderType='Limit' limitPrice=10395 stopPrice=0 quantity=1 tif=Gtc oco='unmanageexitdoco1033108424' filled=0 averageFillPrice=0 onBehalfOf='' id=37262 time='2020-07-02 09:31:55' gtd='2099-12-01' statementDate='2020-07-02'
Datos de La Orden Stop Loss LE orderId='78395b783d85449ebb4c76f4df29fa6e' account='Playback101' name='longStopLoss' orderState=Accepted instrument='NQ 09-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=10367 quantity=1 tif=Gtc oco='unmanageexitdoco1033108424' filled=0 averageFillPrice=0 onBehalfOf='' id=37263 time='2020-07-02 09:31:55' gtd='2099-12-01' statementDate='2020-07-02'
2 Filled
Datos de La Orden Take Profit LE orderId='d35c45ee282441cbafeae857e2d29d1c' account='Playback101' name='longProfitTarget' orderState=Working instrument='NQ 09-20' orderAction=Sell orderType='Limit' limitPrice=10395 stopPrice=0 quantity=4 tif=Gtc oco='unmanageexitdoco1033109023' filled=0 averageFillPrice=0 onBehalfOf='' id=37264 time='2020-07-02 09:31:55' gtd='2099-12-01' statementDate='2020-07-02'
Datos de La Orden Stop Loss LE orderId='8f9f2a589b4141dd84208e89efba3055' account='Playback101' name='longStopLoss' orderState=Accepted instrument='NQ 09-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=10367 quantity=4 tif=Gtc oco='unmanageexitdoco1033109023' filled=0 averageFillPrice=0 onBehalfOf='' id=37265 time='2020-07-02 09:31:55' gtd='2099-12-01' statementDate='2020-07-02'
Cancel Orden
Cancela Orden LE Take Profit por Trail orderId='d35c45ee282441cbafeae857e2d29d1c' account='Playback101' name='longProfitTarget' orderState=Cancelled instrument='NQ 09-20' orderAction=Sell orderType='Limit' limitPrice=10395 stopPrice=0 quantity=4 tif=Gtc oco='unmanageexitdoco1033109023' filled=0 averageFillPrice=0 onBehalfOf='' id=37264 time='2020-07-02 09:32:24' gtd='2099-12-01' statementDate='2020-07-02'
Cancela Orden LE Stop Loss por Trail orderId='d35c45ee282441cbafeae857e2d29d1c' account='Playback101' name='longProfitTarget' orderState=Cancelled instrument='NQ 09-20' orderAction=Sell orderType='Limit' limitPrice=10395 stopPrice=0 quantity=4 tif=Gtc oco='unmanageexitdoco1033109023' filled=0 averageFillPrice=0 onBehalfOf='' id=37264 time='2020-07-02 09:32:24' gtd='2099-12-01' statementDate='2020-07-02'
Trail Stop
Trail Stop LE orderId='d46a5d1a27ad4bbf98388c04027fd723' account='Playback101' name='TP Trail LE' orderState=Accepted instrument='NQ 09-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=10382.25 quantity=5 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=37266 time='2020-07-02 09:32:24' gtd='2099-12-01' statementDate='2020-07-02'
Code:
// Trail Stop Long
if (Position.MarketPosition == MarketPosition.Long && activeTrail)
{
double riskPoint = Math.Abs(targetOrderLE.LimitPrice - Position.AveragePrice);
{
Comment