Login Page - Create Account

Support Board


Date/Time: Mon, 08 Jun 2026 20:18:50 +0000



[Programming Help] - Study has issue with submitting orders

View Count: 245

[2026-04-24 01:07:35]
User944318 - Posts: 55
When I run this study, it correctly enters and exit the first trade of the day as expected, however, any subsequent trades, whether I am reversing position at the exit of the first one or entering a new trade an hour later are ignored (no trade is sent to my broker). Additionally, when I am running a nearly identical study on another chart of the same instrument, its trades are blocked by the trading of this study. For example: I had this and a similar study running on two different ES charts at the same time. They were both supposed to go long at 9:45, exit that position and go short at 10 and exit the short at 10:15. The first study correctly entered at 9:45 and exited at 10, but did not take it's second trade. The second study's trades were not submitted for either trade. I received the success message from both studies for both 9:45 and 10 as expected but the trades were not submitted (it seems like the studies are interpretting the data as expected, but orders are being block), what is going on?


s_SCPositionData PositionData;
sc.GetTradePosition(PositionData);
int position = PositionData.PositionQuantity;
  if (position < 0) {
    s_SCNewOrder exitOrder;
    exitOrder.OrderQuantity = -1*position; // 1 contract or whatever is long
    exitOrder.OrderType = SCT_ORDERTYPE_MARKET;
    exitOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;

    int result = sc.SellExit(exitOrder);
  }
  else if (position > 0) {
    s_SCNewOrder exitOrder;
    exitOrder.OrderQuantity = position; // 1 contract or whatever is long
    exitOrder.OrderType = SCT_ORDERTYPE_MARKET;
    exitOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;

    int result = sc.BuyExit(exitOrder);
  }
  
  if (CurrentHour < 9 || CurrentHour > 10 || (CurrentHour == 9 && CurrentMinute < 28) || (CurrentHour == 10 && CurrentMinute > 16)) {
    return;
  }
  
  if (condition1) {
    s_SCNewOrder NewOrder;
    NewOrder.OrderQuantity = 1;
    NewOrder.OrderType = SCT_ORDERTYPE_MARKET;
    NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;

    int resultS = sc.SellEntry(NewOrder);
    if (resultS == 0) {
if (sc.Index == sc.ArraySize -1)
      {
        //Add error message to the Sierra Chart Message Log for interpretation
        sc.AddMessageToLog(sc.GetTradingErrorTextMessage(resultS), 0);
        sc.AddMessageToLog("FAILURE", 1);
      }
} else {
sc.AddMessageToLog("SUCCESS: Sell Entry Order Submitted!", 1);
}
    
  }
  
  if (condition2) {
    s_SCNewOrder NewOrder;
    NewOrder.OrderQuantity = 1;
    NewOrder.OrderType = SCT_ORDERTYPE_MARKET;
    NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;

    int resultB = sc.BuyEntry(NewOrder);
    if (resultB == 0) {
if (sc.Index == sc.ArraySize -1)
      {
        //Add error message to the Sierra Chart Message Log for interpretation
        sc.AddMessageToLog(sc.GetTradingErrorTextMessage(resultB), 0);
        sc.AddMessageToLog("FAILURE", 1);
      }
} else {
sc.AddMessageToLog("SUCCESS: Sell Entry Order Submitted!", 1);
}
  }
[2026-04-25 05:56:46]
curious16 - Posts: 47
I'd suggest this bit:
exitOrder.OrderQuantity = -1*position; // 1 contract or whatever is long
looks wrong.

Order quantities need to be positive. These were unsigned integers but SC changed the field to double to accommodate trading in fractional lots. The side of an order (buy or sell) is not stored in the sign of OrderQuantity. The side is determined by the command you issue to submit the order. You can use the same s_SCNewOrder structure to buy or sell.
[2026-04-25 22:07:37]
User944318 - Posts: 55
Order quantity is always positive. That is not the issue. My strategy was able to correctly exit any positions it entered correctly. It was an issue with entering.
[2026-04-26 16:00:53]
ForgivingComputers.com - Posts: 1224
Your success/fail test is incorrect.

if (resultS == 0) {
if (sc.Index == sc.ArraySize -1)
{
//Add error message to the Sierra Chart Message Log for interpretation
sc.AddMessageToLog(sc.GetTradingErrorTextMessage(resultS), 0);
sc.AddMessageToLog("FAILURE", 1);
}
} else {
sc.AddMessageToLog("SUCCESS: Sell Entry Order Submitted!", 1);
}

Success is if (resultS > 0) and fail if (results <= 0).

Also, without seeing the entire study, it is unclear why you cannot use this on two charts. However, if they share the same symbol and account, the position data may be causing the other one to fail.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account