Login Page - Create Account

Support Board


Date/Time: Fri, 07 Feb 2025 18:04:21 +0000



Post From: ACSIL - Internal Order ID given to sc.ModifyOrder is 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