Login Page - Create Account

Support Board


Date/Time: Tue, 23 Apr 2024 20:35:45 +0000



Advanced Study: using both Attached Orders and BuyExit/SellExit

View Count: 1497

[2014-03-26 18:24:25]
User24178 - Posts: 4
Hi,
I need a code example on using BuyExit (SellExit) to close a position with Attached Orders. I am trying to do something like this:


if (sc.SetDefaults)
{
sc.SupportAttachedOrdersForTrading = true;
sc.CancelAllWorkingOrdersOnExit = true;
}

... // enter a trade with attached stop/target orders - SC shows entry executed and attached orders in effect

// now, need to force-exit the trade:
s_SCNewOrder order;
order.InternalOrderID = trade.GetEntryOrderId();
order.OrderType = SCT_ORDERTYPE_MARKET;
order.OrderQuantity = trade.GetSize();

int quantity = trade.IsLong() ? sc.BuyExit(order) : sc.SellExit(order);

Always get -1 with the same log message, e.g. "SellExit signal is ignored because Short position quantity does not exist or there are already working exit orders that will flatten the position. Current Position quantity with working exit orders: 0. Current Position quantity with exit market orders: 0 ".

Tried many variations of the above code (e.g. specifying OrderQuantity 0, not specifying InternalOrderId), with the same result.

Please help. Thank you!


[2014-03-27 02:35:10]
Sierra Chart Engineering - Posts: 104368
This is not needed and should not be used:
order.InternalOrderID = trade.GetEntryOrderId();

The main problem we see is at the time you are submitting the Exit order, it does not look like there is a position:
Current Position quantity with exit market orders: 0

Unless there is already a market order which is going to flatten the position.
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
[2014-03-31 17:13:06]
User24178 - Posts: 4
Assuming that I have several open trades, each with its own attached target/stop orders, how do I specify which trade I am exiting? That was my idea behind
"order.InternalOrderID = trade.GetEntryOrderId();"
Since you say this is not to be used, what is the proper way to relate my exit order to an existing trade?

Thank you.
Date Time Of Last Edit: 2014-03-31 17:13:41
[2014-03-31 17:27:32]
Sierra Chart Engineering - Posts: 104368
All trades are treated as a single Trade Position and any new orders entered which will offset that Position, just simply offset that Position as a whole.
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
[2014-03-31 18:17:23]
User24178 - Posts: 4
In the presence of Attached orders, though, the system would have to cancel some of them to account for the decrease in the position size, is that correct?

Please see the attached trading log that shows a position of 10000 GBPUSD, with open Stop Loss and Take Profit Buy orders. In this situation, my study tries to close the position using code like this:

s_SCNewOrder NewOrder;
NewOrder.OrderQuantity = 10000; // full position size
NewOrder.OrderType = SCT_MARKET;

int quantity = sc.SellExit(NewOrder);

The result is

Auto-Trading: GBPUSD 1 Min #1 | Move Retracement | SellExit signal is ignored because Short position quantity does not exist or there are already working exit orders that will flatten the position. Current Position quantity with working exit orders: 0. Current Position quantity with exit market orders: 0 | 2014-03-31 13:18:02

Can you advise on the proper way to force-close a position like this?
Would it help if I cancelled the attached orders first?

Thank you.

Private File
[2014-04-02 02:20:50]
Sierra Chart Engineering - Posts: 104368
We are going to be testing this now to see if we can duplicate the issue.
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
[2014-04-02 04:01:05]
Sierra Chart Engineering - Posts: 104368
We have gone through a detailed test procedure and what this has revealed is that you are using the wrong function. You have entered with a Buy order and therefore you must use sc.BuyExit.

Use this function and it should work properly.

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

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

Login

Login Page - Create Account