Login Page - Create Account

Support Board


Date/Time: Mon, 10 Mar 2025 03:13:22 +0000



Post From: Orders not Cancelling (fast replay) + Checking if existing working order or filled order

[2022-03-12 15:27:39]
1+1=10 - Posts: 270
Hi SelimEker,

Backtesting and replays in SC can be tricky. I don't use that functionality so sadly can't provide must help. But as to your other concern:

Also. Any ideas on how to check (programatically) whether there is already an order (that is placed (not filled) or in the market until exited) instead of using my global variable ?

Yes, User431178's idea of using trade position data is most ideal. You want something like this:

s_SCPositionData position_data;
sc.GetTradePosition(position_data);

// CANCEL BUY OR SELL ORDERS
if (position_data.NonAttachedWorkingOrdersExist)
{

s_SCTradeOrder entry_order;
if (
sc.GetOrderByOrderID (scalp_entry_order_id, entry_order) != SCTRADING_ORDER_ERROR
&& entry_order.FilledQuantity < entry_order.OrderQuantity
&& IsWorkingOrderStatusIgnorePendingChildren(entry_order.OrderStatusCode)
)
{
// This strategy canceled entry buy limit orders as soon as the bid price
// was > 2 ticks above our buy limit order price. You could modify the
// the cancellation reason(s) below:

bool should_cancel_buy_trade = entry_order.BuySell == BSE_BUY &&
(last_bid_price - entry_order.Price1 > 1.9 * sc.TickSize);

bool should_cancel_sell_trade = entry_order.BuySell == BSE_SELL &&
(entry_order.Price1 - last_asl_price > 1.9 * sc.TickSize);


if (should_cancel_buy_trade || should_cancel_sell_trade)
{
sc.CancelOrder(scalp_entry_order_id);
}
}
}