I am developing a strategy that places two OCO orders at the same price and time. One of the OCO orders has associated stop and profit target. The other OCO has an associated stop only. The goal is to enter with two contracts at the same price, divest one of the contracts at a small profit target and let the other contract run, with a trailing stop. I have the strategy largely working.
Each OCO order has a unique ID. I use managed code to update each OCO leg in C# code. The problem is that the the OCO orders are both being executed at the first OCO's profit target. This puzzling because the 2nd OCO does not have a profit target. I have used the TraceOrders feature to capture the sequence of events (full log included as an attachment.) I see somethings in this log that I don't understand.
Find below a snippet of the TraceOrders generated by this strategy:
OCO order with a Stop and profit target (two legged OCO) : Signal='YM-20S-1-STD-L-A' oco='1fc9340ab894463bb45449e5ef335b50'
OCO order with Stop only (one legged OCO): FromEntrySignal='YM-20S-1-STD-L-B' oco='147637e606f34ed9accff3291c10ab76'
Each OCO has 1 contract.
All of the orders of each OCO reference quantity=1. All is as expected until I move both OCO stop legs to BreakEven plus one tick. For some unexplained reason, both OCO Stop orders now have a quantity=2. While there is no log evidence of this, the 'Profit Target' must be also changed to a quantity of 2, because when the 'Profit Target' is hit, BOTH OCOs are closed at the 'Profit Target' price. I expected only the OCO Signal='YM-20S-1-STD-L-A' to be executed and the 'YM-20S-1-STD-L-B' leg to still be active. I am under the impression that using unique signal names keeps the each OCO's orders independent.
Also, when I tested this using Strategy analyzer. The trade executed as expected in the backtest. Only the 'YM-20S-1-STD-L-A' leg completes at the profit target and 'YM-20S-1-STD-L-B' leg continues.
The appears as if this is only a problem when trading against the real-time simulator. I did test this on other days, and the behavior is still not working as I expect.
What is the problem be?
Thanks for your help.
Output from the TraceOrders event:
75. 1/4/2021 1:29:03 PM, 1/4/2021 1:33:00 PM, SimAccount4, 202, YM, 20S-, Strategy 'TradeSafeAutomated04/189138844': Amended stop order orderId='ad1f33e6527e47eb8011107d2dd1fbc2' account='SimAccount4' name='Stop loss' orderState=ChangePending instrument='YM 03-21' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=29982 quantity=1 tif=Gtc oco='147637e606f34ed9accff3291c10ab76' filled=0 averageFillPrice=0 onBehalfOf='' id=15263 time='2021-01-04 13:29:03' gtd='2099-12-01' statementDate='2021-01-04' stopPriceChanged=29990
76. 1/4/2021 1:29:03 PM, 1/4/2021 2:00:00 PM, SimAccount4, 201, YM, 20S-, Strategy 'TradeSafeAutomated04/189138844': Amended target order orderId='8edb21d051cb4e5ea7d1964b977bf85f' account='SimAccount4' name='Profit target' orderState=ChangePending instrument='YM 03-21' orderAction=Sell orderType='Limit' limitPrice=30005 stopPrice=0 quantity=1 tif=Gtc oco='1fc9340ab894463bb45449e5ef335b50' filled=0 averageFillPrice=0 onBehalfOf='' id=15262 time='2021-01-04 13:29:03' gtd='2099-12-01' statementDate='2021-01-04' limitPriceChanged=30005
77. 1/4/2021 1:29:03 PM, 1/4/2021 2:00:00 PM, SimAccount4, 201, YM, 20S-, Strategy 'TradeSafeAutomated04/189138844': Amended stop order orderId='487c90c341ac45bc9b98805177f3613d' account='SimAccount4' name='Stop loss' orderState=ChangePending instrument='YM 03-21' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=29982 quantity=1 tif=Gtc oco='1fc9340ab894463bb45449e5ef335b50' filled=0 averageFillPrice=0 onBehalfOf='' id=15261 time='2021-01-04 13:29:03' gtd='2099-12-01' statementDate='2021-01-04' stopPriceChanged=29990
78. 1/4/2021 1:29:03 PM, 1/4/2021 2:00:00 PM, SimAccount4, 201, YM, 20S-, Strategy 'TradeSafeAutomated04/189138844': Amended stop order orderId='ad1f33e6527e47eb8011107d2dd1fbc2' account='SimAccount4' name='Stop loss' orderState=ChangePending instrument='YM 03-21' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=29982 quantity=1 tif=Gtc oco='147637e606f34ed9accff3291c10ab76' filled=0 averageFillPrice=0 onBehalfOf='' id=15263 time='2021-01-04 13:29:03' gtd='2099-12-01' statementDate='2021-01-04' stopPriceChanged=29990
79. >>Move Profit Stop Stop Target: 30001 (my diagnostic print)
80. 1/4/2021 1:29:06 PM, 1/4/2021 1:29:20 PM, SimAccount4, 3422, YM, 20S-, Strategy 'TradeSafeAutomated04/189138844': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='YM-20S-1-STD-L-B' Mode=Price Value=30001 IsSimulatedStop=False IsMarketIfTouched=False
81. 1/4/2021 1:29:06 PM, 1/4/2021 1:29:20 PM, SimAccount4, 3422, YM, 20S-, Strategy 'TradeSafeAutomated04/189138844': Amended stop order orderId='ad1f33e6527e47eb8011107d2dd1fbc2' account='SimAccount4' name='Stop loss' orderState=Accepted instrument='YM 03-21' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=29990 quantity=2 tif=Gtc oco='147637e606f34ed9accff3291c10ab76' filled=0 averageFillPrice=0 onBehalfOf='' id=15263 time='2021-01-04 13:29:03' gtd='2099-12-01' statementDate='2021-01-04' stopPriceChanged=30001
82. 1/4/2021 1:29:06 PM, 1/4/2021 1:29:20 PM, SimAccount4, 3422, YM, 20S-, Strategy 'TradeSafeAutomated04/189138844': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='YM-20S-1-STD-L-A' Mode=Price Value=30001 IsSimulatedStop=False IsMarketIfTouched=False
83. 1/4/2021 1:29:06 PM, 1/4/2021 1:29:20 PM, SimAccount4, 3422, YM, 20S-, Strategy 'TradeSafeAutomated04/189138844': Amended stop order orderId='487c90c341ac45bc9b98805177f3613d' account='SimAccount4' name='Stop loss' orderState=Accepted instrument='YM 03-21' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=29990 quantity=2 tif=Gtc oco='1fc9340ab894463bb45449e5ef335b50' filled=0 averageFillPrice=0 onBehalfOf='' id=15261 time='2021-01-04 13:29:03' gtd='2099-12-01' statementDate='2021-01-04' stopPriceChanged=30001
Segment of the orderOrder grid from the Control Center
YM 03-21 | Sell | Stop Market | 2 | 0 | 30001 | Cancelled | 0 | 0 | 2 | Stop loss | TradeSafeAutomated04 | 147637e606f34ed9accff3291c10ab76 | GTC | SimAccount4 | ad1f33e6527e47eb8011107d2dd1fbc2 | 1/4/2021 13:29:06 | |
YM 03-21 | Sell | Stop Market | 2 | 0 | 30001 | Cancelled | 0 | 0 | 2 | Stop loss | TradeSafeAutomated04 | 1fc9340ab894463bb45449e5ef335b50 | GTC | SimAccount4 | 487c90c341ac45bc9b98805177f3613d | 1/4/2021 13:29:06 | |
YM 03-21 | Sell | Limit | 2 | 30005 | 0 | Filled | 2 | 30005 | 0 | Profit target | TradeSafeAutomated04 | 1fc9340ab894463bb45449e5ef335b50 | GTC | SimAccount4 | 8edb21d051cb4e5ea7d1964b977bf85f | 1/4/2021 13:29:06 | |
YM 03-21 | Buy | Stop Limit | 1 | 30000 | 30000 | Filled | 1 | 30000 | 0 | YM-20S-1-STD-L-B | TradeSafeAutomated04 | GTC | SimAccount4 | 089bedd545bd46889d60b43cfb5a5cc2 | 1/4/2021 13:29:04 | ||
YM 03-21 | Buy | Stop Limit | 1 | 30000 | 30000 | Filled | 1 | 30000 | 0 | YM-20S-1-STD-L-A | TradeSafeAutomated04 | GTC | SimAccount4 | f41626be0e3845e4a6f6ad56649d1f26 | 1/4/2021 13:29:03 |
Comment