Login Page - Create Account

Support Board


Date/Time: Fri, 26 Apr 2024 22:11:46 +0000



[User Discussion] - Stoploss rejected in ACSIL auto trading system

View Count: 861

[2020-08-01 09:43:18]
User820318 - Posts: 40
Hi,

I am developing an autotrading system for ETH/USD via Bitmex and have been live testing for the last week. Just now I had a very unfortunate event. It would appear that as the system was making an order modification the stoploss order was rejected and the position was therefore left unprotected. Obviously this is unsustainable for any trading system. I have the below piece of code which is supposed to protect against having no stops however because the profit target order was still in place this failed to flatten the position. Do you have any advice as to how to prevent this kind of event from happening in the future?

Thanks in advance for your assistance.

// Flatten if position open with no working orders
  if (PositionData.PositionQuantity != 0 &&
    !PositionData.WorkingOrdersExist)
  {
    sc.FlattenPosition();
    sc.AddMessageToLog("Position exists with no working orders. Position was Flattened.", 1);
  }
Date Time Of Last Edit: 2020-08-01 09:46:42
imageInkedCapture_LI.jpg / V - Attached On 2020-08-01 09:46:11 UTC - Size: 5.34 MB - 231 views
[2020-08-01 12:13:14]
User820318 - Posts: 40
and another instance of this happening again today - see attached. Stop loss order cancelled leaving the position open and unprotected. What could be causing this behaviour?
imageCapture2.PNG / V - Attached On 2020-08-01 12:12:06 UTC - Size: 71.94 KB - 209 views
Attachment Deleted.
[2020-08-01 12:26:44]
Sierra Chart Engineering - Posts: 104368
This is a problem with BitMex. It is just how the BitMex system works. Makes no sense.
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
[2020-08-01 12:32:39]
User820318 - Posts: 40
Thanks for the quick reply. Is there anything I can do to mitigate this? For example the error seems to come when the order is being updated. This is a set and forget system in that once the stop and target are put in place they dont need to be updated until one or the other is hit. Is there a way to circumvent these order updates? Or at least put a mechanism in place to flatten the position if there is an open position without a working stoploss order? How would I do that?

Thanks for your time.
[2020-08-01 16:04:02]
User820318 - Posts: 40
Following this thread... One way to do this would be to quantify the number of working orders and if it falls below 2 (i.e. one stop loss and one take profit) flatten the position. Is there a way in ACSIL to quantify the number of working orders?

I have found "PositionQuantityWithAllWorkingOrders" but it seems that wont work because the documentation says "In the case of when there are two orders in an OCO group, the quantity of only one of those orders is counted". Is there another mechanism to count the number of working orders?

Thanks in advance for your assistance.
[2020-08-01 19:40:50]
bradh - Posts: 854
You can check the nearest stop and target individually and make sure they are both open.

  s_SCTradeOrder ExistingStopOrder;
  int OrderResult = sc.GetNearestStopOrder(ExistingStopOrder);

[2020-08-01 21:26:10]
User820318 - Posts: 40
Thanks very much.

Something like the below?

// Flatten if position open with no working orders
s_SCTradeOrder ExistingStopOrder;
int OrderResult = sc.GetNearestStopOrder(ExistingStopOrder);

if (PositionData.PositionQuantity != 0 &&
!OrderResult)
{
sc.FlattenPosition();
sc.AddMessageToLog("Position exists with no stop. Position was Flattened.", 1);
}
[2020-08-01 21:29:54]
bradh - Posts: 854
I would add a check of the order status to see if it is open.
[2020-08-01 21:47:34]
User820318 - Posts: 40
Thanks.

Doesnt PositionData.PositionQuantity != 0 tell us that? if position quantity is not zero then there must be an open position?

Should I add

IsWorkingOrderStatus(ExistingOrder.OrderStatusCode) !=0

to the if statement also?
[2020-08-01 22:09:10]
bradh - Posts: 854
PositionQuantity is open contracts. No order information there.

if (PositionData.PositionQuantity != 0 && ExistingOrder.OrderStatusCode != SCT_OSC_OPEN)
{
// flatten and cancel
}

Date Time Of Last Edit: 2020-08-01 22:12:31
[2020-08-01 22:26:38]
User820318 - Posts: 40
Thanks. You are using

ExistingOrder.OrderStatusCode != SCT_OSC_OPEN

to make sure there are no unfilled entry orders?

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

Login

Login Page - Create Account