Login Page - Create Account

Support Board


Date/Time: Fri, 19 Apr 2024 19:27:56 +0000



[Programming Help] - Automated Trading From an Advanced Custom Study::Cancel bug or user error/misunderstanding

View Count: 175

[2023-05-24 23:58:10]
lakenymph - Posts: 2
Hi SC Support:
In working through a proof of concept in using SC for trading support I’ve come across the following issue in testing order cancelling.

Using Unmanaged Automated Trading settings as defined at URL:
Automated Trading Management: Unmanaged Automated Trading

Use Case: Need to change an Entry limit order to a market order.

Constraints: Can’t use sc.ModifyOrder because this method only allows price and qty to be changed and there appears to be no other sc.* method to support order type modifications.

Solution:
1) Cancel Limit via sc.CancelOrder(Order ID) Order
2) Verify Cancel Completion via sc.GetOrderByOrderID(Order ID, s_SCTradeOrder object)
3) Create Market Order via sc.BuyOrder | sc.SellOrder since trade settings are unmanaged

The issue is that when sc.GetOrderByOrderID checks for status in the sc processing loop the retu s_SCTradeOrder object is undefined where OrderStatusCode == SCT_OSC_UNSPECIFIED and is not SCT_OSC_PENDINGCANCEL || SCT_OSC_CANCELED.

Using an order search process via the sc.GetOrderByIndex(Index, s_SCTradeOrder object) method the order can be found with the desired SCT_OSC_CANCELED status.

It seems that this is a bug or misunderstanding on my end of correctly in correctly interfacing with the sc ACSL interface.

Should not a call to sc.GetOrderByOrderID method return a valid order object with its status as either SCT_OSC_PENDINGCANCEL | SCT_OSC_CANCELED?

Thanks in advance for your feedback.
[2023-05-25 04:25:04]
lakenymph - Posts: 2
The following function seems to be a reasonable workaround:

  bool SetSCTradeOrder(SCStudyInterfaceRef sc, int const ordID, s_SCTradeOrder &ord)
  {
sc.GetOrderByOrderID(ordID, ord);

    if (ord.OrderType == SCT_OSC_UNSPECIFIED || ord.InternalOrderID != ordID)
    { //Search by 2nd method:
      int Index = 0;
      while (sc.GetOrderByIndex(Index, ord) != SCTRADING_ORDER_ERROR)
      {
        Index++;
        if (ord.InternalOrderID == ordID)
          break;
      }
    }

    return ord.InternalOrderID == ordID;
  }

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

Login

Login Page - Create Account