Support Board
Date/Time: Mon, 15 Sep 2025 13:35:06 +0000
[Programming Help] - Autotrader live order modification fails
View Count: 97
[2025-09-11 11:49:08] |
User327556 - Posts: 7 |
Hey, I have created my own autotrader within ASCIL. Everything seems to be working in sim, Placement of orders to cancelation of the attached orders when profit target is hit. However, when connected to my broker (rithmic), this seems to work differently. When a target is filled, rithmic cancels the order within their server so it is not exsistent, while in sierra the order remains active creating a ghost order. It will not fill, but it is there and locks the autotrading (no trades when active orders or positions). the code for the target 1 (2 / 3 are identical): NewOrder.Target1Offset = Input_target1_fixed_value.GetInt() * sc.TickSize; NewOrder.AttachedOrderTarget1Type = SCT_ORDERTYPE_LIMIT; NewOrder.OCOGroup1Quantity = Target1Quantity_short; the code for the stop 1 ( 2/3 are identical just different group): if(Target1Quantity_short>0){
NewOrder.Stop1Offset=Stop_price_short; NewOrder.OCOGroup1Quantity=Target1Quantity_short; NewOrder.AttachedOrderStop1Type=SCT_ORDERTYPE_STOP; } In the tradingsettings I have turned on: Use server side bracket orders (if supported)
Use server side OCO orders (if supported) When I add an extra line to flatten and cancel everything after trade position is closed, it rejects because the order doesn't exsist at rithmic. Do you guys have any idea what I could do to fix it? Kind regards, |
[2025-09-12 17:33:48] |
ForgivingComputers.com - Posts: 1122 |
When I add an extra line to flatten and cancel everything after trade position is closed, it rejects because the order doesn't exist at rithmic.
When the position is closed due to a stop or target being hit, the "sibling" order (the target or stop respectively) is automatically cancelled. You should not need to do anything after the position is closed. However, if you do want to Flatten and Cancel (while the position is open) you should pre-check to see if there is a position and/or orders to cancel to avoid an error. Rule #1: Only send flatten and cancel if there is an open position. Rule #2: If no Open Position and there are still working orders then Cancel all orders s_SCPositionData PositionData;
sc.GetTradePosition(PositionData); if (PositionData.PositionQuantity != 0) { sc.FlattenAndCancelAllOrders(); } else if (PositionData.WorkingOrdersExist) { sc.CancelAllOrders(); } |
[2025-09-13 11:56:29] |
User327556 - Posts: 7 |
Hi, When the position is closed due to a stop or target being hit, the "sibling" order (the target or stop respectively) is automatically cancelled. You should not need to do anything after the position is closed.
The issue is that one of the orders is not always canceled, then the whole autotrading freezes because sierra recognises a ghost order while rithmic doesn't. My last statement about cancel and flatten was about trying to get rid of that order, so autotrading can be resumed. When I try to cancel the order, rithmic sends an error back because it doesn't recognise the order. Thanks for your response! |
[2025-09-13 14:12:24] |
ForgivingComputers.com - Posts: 1122 |
If the above code is not detecting canceled (non-working) orders, then I would think the problem is with Rithmic.
|
[2025-09-13 15:03:43] |
User327556 - Posts: 7 |
The code is detecting the orders, however to cancel an order sierra sends the cancelation to rithmic. The setup has 2 OCO groups, target 1 and target 2. If T1 is hit, Rithimc automatically cancels the SL (oco1). However, it doesn't send a cancelation notification to sierra. So when sierra gets the response that T1 is filled, Sierra wants to cancel the order and sends the cancelation to rithmic. Rithmic then sends a rejection / error in return because it doesn't recognise the order. Sierra gets the error / rejection and keeps the order kinda like a ghost order, because it is not canceled on the broker side.. Thanks again, |
[2025-09-13 15:45:00] |
ForgivingComputers.com - Posts: 1122 |
You can check to see if the order is canceled or non-existent before sending the cancel order.
|
To post a message in this thread, you need to log in with your Sierra Chart account: