Support Board
Date/Time: Fri, 07 Feb 2025 14:56:59 +0000
ACSIL - Internal Order ID given to sc.ModifyOrder is 0
View Count: 1794
[2020-05-26 14:14:31] |
User704508 - Posts: 20 |
Hi, I'm having issues with the Internal Order ID in an algo. It works well in SIM mode, but when it's live, the Internal Order ID that I save in a persistent variable doesn't seem to work and I get the following error: "Internal Order ID given to sc.ModifyOrder is 0". Any idea why it does that? Thanks! |
[2020-06-03 15:56:35] |
User704508 - Posts: 20 |
I think there is an issue with the sc.ModifyOrder since the last updates. I noticed on all my strategies that whenever I use the sc.ModifyOrder function, it closes the position instead. Could you please do something about this? |
[2020-06-03 18:03:05] |
|
If you are getting this error it must be true: "Internal Order ID given to sc.ModifyOrder is 0". We want you to recompile the study using the Remote Build functionality on the current version: How to Build an Advanced Custom Study from Source Code: Step-By-Step Instructions Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service: Sierra Chart Teton Futures Order Routing Date Time Of Last Edit: 2020-06-03 18:03:33
|
[2020-06-03 18:10:35] |
User704508 - Posts: 20 |
I will recompile all my custom studies and will let you know if that worked (once a trade is placed with the right conditions). Do I also need to remove every study from the chart settings and put it back in it? It's usually not necessary but maybe I should? Also, I don't really understand why that would fix the problem since the trades are placed according to the strategies. It's just the sc.ModifyOrder that doesn't work. That's doesn't seem logical. Date Time Of Last Edit: 2020-06-03 18:15:11
|
[2020-06-04 07:01:21] |
|
We do not know what the cause is. We are just simply trying to give the best answer that we can. A recompile should not be needed. But we definitely do not believe there is any problem with the ModifyOrder ACSIL function. You do not have to remove the studies. Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service: Sierra Chart Teton Futures Order Routing Date Time Of Last Edit: 2020-06-04 07:01:38
|
[2020-06-04 20:11:42] |
ForgivingComputers.com - Posts: 995 |
How are you determining the Order ID? Are you checking to see if it is zero before calling sc.ModifyOrder? You may want to do a test to see if the lookup method you are using has completed successfully. There may be a timing issue with live data and you need to wait for a valid order ID. |
[2020-06-04 23:39:41] |
|
There could not be a timing issue. What is used is the Internal Order ID which is set upon the submission of an order.
Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service: Sierra Chart Teton Futures Order Routing Date Time Of Last Edit: 2020-06-04 23:39:52
|
[2020-06-05 15:17:58] |
User704508 - Posts: 20 |
I recompiled every strategy that I have but it did not fix the issue. Do you think it might be a problem because of the code below? I created this because I had issues with order reversing themselves when getting flat and I didn't want any open orders without stop losses running around. I tested it and never had any problem before but I don't see any other solution here. s_SCTradeOrder OrderDetails;
int Index = 0; if(PositionData.PositionQuantity != 0) { while(sc.GetOrderByIndex(Index, OrderDetails) != SCTRADING_ORDER_ERROR) { Index++; // increment the index if (OrderDetails.OrderStatusCode == SCT_OSC_OPEN) { openOrder = 1; break; } } if(openOrder == 0) { sc.FlattenAndCancelAllOrders(); } } Date Time Of Last Edit: 2020-06-05 15:35:29
|
[2020-06-05 21:48:13] |
ForgivingComputers.com - Posts: 995 |
Your original issue was "Internal Order ID given to sc.ModifyOrder is 0". You were trying to modify an order price or quantity, and it was getting rejected due to a non-existent order ID. I recommend you don't look up the order that way. Instead, when the order is filled, you should save a persistent variable of the order id(s): ParentOrderID = NewOrder.InternalOrderID;
When there are no open orders, you should reset ParentOrderID to 0. If you want to flatten and cancel any open positions that have no working orders, then this is easier: s_SCPositionData PositionData; sc.GetTradePosition(PositionData); { if (PositionData.PositionQuantity != 0 && PositionData.WorkingOrdersExist) { sc.FlattenAndCancelAllOrders(); sc.AddMessageToLog("Open Position with No Working Orders. Position Flattened.", 0); } } |
[2020-06-06 10:54:09] |
User704508 - Posts: 20 |
The code I sent in my previous message is a piece of code I put in a different algo running at the same time to avoid having open orders if something goes wrong. But I'll try the piece of code you sent (@bradh), it does look simpler and more efficient. Thank you very much for that! My original issue is that whenever I call sc.ModifyOrder (since I updated Sierra), it flattens my position. And the only message I get from the trade service log is "Internal Order ID given to sc.ModifyOrder is 0". First, I don't understand why I get this message, because if the order ID provided was 0, how could it actually modify the order and flattens the position? Second, the way I modify orders has always been working since I created my first algo and I use the same piece of code in every strategy where I have a trailing stop loss, so why would an issue occurs now? Third, it works fine in SIM but not live. If the error was related to the code and the way I provide the internal order id, I don't think it would work in a sim environment either. So how is this possible? Below is the code I actually use to place and modify the order (I removed a bunch of if statements in the code below but the part where the stop loss is updated is done at the end of each bar): int& Stop1OrderIDESSupportLong = sc.GetPersistentInt(2); double& NewPossibleStop = sc.GetPersistentDouble(1); double& orderStop = sc.GetPersistentDouble(2); double& currentStop = sc.GetPersistentDouble(3); // Create a market order and enter long. s_SCNewOrder NewOrder; NewOrder.TextTag = "ES 1m Support Long"; NewOrder.OrderQuantity = 1; NewOrder.OrderType = SCT_ORDERTYPE_MARKET; NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED; NewOrder.OCOGroup1Quantity = 1; NewOrder.Stop1Price = currentPrice - 12*sc.TickSize; sc.BuyEntry(NewOrder); // Remember the order ID for subsequent modification and cancellation Stop1OrderIDESSupportLong = NewOrder.Stop1InternalOrderID; OrderId = NewOrder.InternalOrderID; orderStop = currentPrice - 12*sc.TickSize; currentStop = orderStop; s_SCTradeOrder StopOrder; sc.GetOrderByOrderID(Stop1OrderIDESSupportLong, StopOrder); NewPossibleStop = currentLow - 36*sc.TickSize; if(StopOrder.OrderStatusCode == SCT_OSC_OPEN && PositionData.PositionQuantity != 0 && NewPossibleStop > currentStop && NewPossibleStop > orderStop) { s_SCTradeOrder ExistingOrder; if(sc.GetOrderByOrderID(OrderId, ExistingOrder) != SCTRADING_ORDER_ERROR && ExistingOrder.OrderStatusCode == SCT_OSC_FILLED) { s_SCNewOrder ModifyOrder; ModifyOrder.InternalOrderID = Stop1OrderIDESSupportLong; ModifyOrder.Price1 = NewPossibleStop; sc.ModifyOrder(ModifyOrder); currentStop = NewPossibleStop; } } Date Time Of Last Edit: 2020-06-06 10:56:00
|
[2020-06-06 11:36:38] |
ForgivingComputers.com - Posts: 995 |
Second, the way I modify orders has always been working since I created my first algo and I use the same piece of code in every strategy where I have a trailing stop loss, so why would an issue occurs now?
If it worked live in a previous version, then you should be able to pin down the version it stopped working at by going back and recompiling on older versions and testing. There have been a number of changes since version 2092. IF the trade is being flattened as a result of the sc.ModifyOrder error, then there should be a record of why it is being flattened in the Trade Activity Log. Something else may be going on. Also, this section of code may not be executing as expected. I would debug all the parameters to confirm their values: if(StopOrder.OrderStatusCode == SCT_OSC_OPEN && PositionData.PositionQuantity != 0 && NewPossibleStop > currentStop && NewPossibleStop > orderStop) { s_SCTradeOrder ExistingOrder; if(sc.GetOrderByOrderID(OrderId, ExistingOrder) != SCTRADING_ORDER_ERROR && ExistingOrder.OrderStatusCode == SCT_OSC_FILLED) { ... } Good Luck! |
To post a message in this thread, you need to log in with your Sierra Chart account: