Login Page - Create Account

Support Board


Date/Time: Fri, 27 Dec 2024 00:38:00 +0000



[Programming Help] - sc.SellEntry and sc.SellExit for a STOP_LIMIT_ORDER

View Count: 1343

[2016-04-02 02:58:49]
@sstfrederik - Posts: 404
I had a sc.SellEntry(myorder) filled as a stop limit order. two orders were attached, one limit order and one trailing stop.

When sc.SellExit(myorder) gets called a few bars later the attached orders are cancelled. The order that should flatten the position is not doing that. The buy stop limit that is send has a price1 of 0. Therefore it keeps the sell position open.

What am I missing here?

thanks.
[2016-04-02 09:43:19]
Sierra Chart Engineering - Posts: 104368
When sc.SellExit(myorder) gets called a few bars later the attached orders are cancelled.
Refer to:
https://www.sierrachart.com/index.php?page=doc/doc_AutoTradeManagment.php#CancelAllWorkingOrdersOnExit



The buy stop limit that is send has a price1 of 0. Therefore it keeps the sell position open.
If you are using a Stop order type with sc.SellExit, then make sure you specify a Price1.
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
[2016-04-02 10:00:22]
@sstfrederik - Posts: 404
Attached orders being cancelled is expected. The price1 not being correct is not, since its the same order details are used as the sellentry order which does have a price1. Does a call to s_SCNeworder myorder object wipe out a previously set price1 on the myorder object? That might explain this.
[2016-04-02 10:05:22]
Sierra Chart Engineering - Posts: 104368
You have to specify the price. Always make sure the s_SCNewOrder::Price1 is set.

Without seeing your code, we do not know exactly what is happening, but it is only proper to always set the price as needed.
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
[2016-04-02 13:16:21]
@sstfrederik - Posts: 404
General code looks like below. Seems that price1 of object MyOrder is not remembered.

//market order object
s_SCNewOrder MyOrder;
MyOrder.TimeInForce = SCT_TIF_GTC;
MyOrder.OrderQuantity = PositionSize;
MyOrder.OrderType = SCT_ORDERTYPE_STOP_LIMIT;
MyOrder.AttachedOrderTarget1Type = SCT_ORDERTYPE_LIMIT;
MyOrder.AttachedOrderStop1Type = SCT_ORDERTYPE_TRAILING_STOP;

if(somecondition){
MyOrder.Stop1Offset = something;
MyOrder.Target1Offset = something;
MyOrder.Price1 = myprice;
sc.BuyEntry(MyOrder);


}


if(someotherconditionatsomeothertime){
sc.BuyExit(MyOrder);

}



If I place price1 in a persistent float and declare it again before calling BuyExit. It seems to work. Is this the correct approach?

thanks.
[2016-04-02 15:33:34]
@sstfrederik - Posts: 404
this could also lead to a lmt stop order waiting to be filled. I was expecting that an exit order would actually exit the open position. I will likely set price1 at the ask or bid just before calling the exit order, which has the highest change of filling. and not getting stuck with an open position and some far away exit order.
Date Time Of Last Edit: 2016-04-02 16:24:10
[2016-04-02 22:30:09]
Sierra Chart Engineering - Posts: 104368
These are general programming questions and it should be obvious to you what to do. The way the code works in post 5 is inherently unreliable.

If I place price1 in a persistent float and declare it again before calling BuyExit. It seems to work. Is this the correct approach?
Yes. But this is a programming help question.

We do not provide programming help. Do not rely on us for programming help. We are leaving this thread and marking it as a Programming Help thread.
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
Date Time Of Last Edit: 2016-04-02 22:30:44
[2016-04-03 17:11:30]
@sstfrederik - Posts: 404
I only posted code because of the reply in post #4.

From documentation and source examples it was not fully clear to me how an exit order works. I was under the impression that the order objects had to be identical for the entry and exit order. From my current understanding I see it is possible to have for example a BuyEntry with a stop limit order type and a BuyExit as a market order.

It might help others if this can be stated in the documentation or in a code example. If the above is not correct I would appreciate further explanation.
[2016-04-04 06:46:10]
Sierra Chart Engineering - Posts: 104368
You can use different order types for both the Entry and the Exit.

The basic problem is this object is not persistent between study function calls:

s_SCNewOrder MyOrder;


And this condition may not be true
if(somecondition)

When this condition is true:
if(someotherconditionatsomeothertime)

Resulting in unset members.
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