Login Page - Create Account

Support Board


Date/Time: Fri, 03 May 2024 12:22:01 +0000



[Programming Help] - replacing stop order with trailing order

View Count: 599

[2021-02-16 20:27:10]
User61576 - Posts: 418
I am entering a position with maket order and a stop
after achieving target 1 I would like to update my stop to trailing stop

as of now, I managed to update my stop to move to b/e but failing with the trailing

this is how I update my stop to be b/e
newStopPrice = mktPrice + (1 * sc.TickSize);//calc of b/e + 1 tick
s_SCNewOrder ModifyOrder;
ModifyOrder.InternalOrderID = mktBuyStop1OrderID;
ModifyOrder.OrderQuantity = totalBuyOrderSubmitted - totalExits;
ModifyOrder.Price1 = newStopPrice;
sc.ModifyOrder(ModifyOrder);

and this is what I am trying to do with the trailing
s_SCNewOrder ModifyOrder;
ModifyOrder.InternalOrderID = mktBuyStop1OrderID;
ModifyOrder.OrderQuantity = totalBuyOrderSubmitted - totalExits;
ModifyOrder.OrderType = SCT_ORDERTYPE_TRAILING_STOP;
ModifyOrder.StopAllOffset = 8 * sc.TickSize;
sc.ModifyOrder(ModifyOrder);

a practical example will be appreciated

thanks
[2021-02-16 23:04:00]
58LesPaul - Posts: 429
I was wondering the same thing. Looks like they could make it possible to edit the active stop like you can with the quantity but instead change the type.

I'm new to SC, may I ask what you do with that code to get it to work? Do you make it a custom Control bar button or how does it work?

Thanks
[2021-02-17 15:17:53]
User99735 - Posts: 234
Hi,
No need to modify the order. Check out csf_TradingExample2WithAdvancedAttachedOrders example in tradingsystem.cpp. Both BreakEven and a trailing stop, can be setup as attached orders, when creating the original order.

Regards

Vivek
[2021-02-17 16:05:09]
User61576 - Posts: 418
I saw that example but my order management was written a long time ago and I don't want to rewrite it. just wanted to add an option of trailing stop only after target 1 is filled.

i tried this as well but it's not working:
sc.CancelOrder(mktBuyStop1OrderID);//cancell the original stop order as I can not update it's type                    
  s_SCNewOrder NewOrder;
  NewOrder.OrderQuantity = totalBuyOrderSubmitted - totalExits;
  NewOrder.StopAllOffset = mktPrice + 8 * sc.TickSize;
  NewOrder.AttachedOrderStopAllType = SCT_ORDERTYPE_TRAILING_STOP;
  NewOrder.TrailStopStepPriceAmount = mktPrice + 4 * sc.TickSize;
  int Result = (int)sc.SellEntry(NewOrder);

I will be happy to learn what I am doing wrong
thanks
[2021-02-19 15:44:55]
bradh - Posts: 854
You don't need to cancel the stop order, nor change its type. All you need to do is save the StopOrderID as a persistent variable after it is filled (Result > 0). Later, to move the stop, you use sc.ModifyOrder() to change the Price1 of the StopOrderID.
[2021-02-20 17:02:29]
User61576 - Posts: 418
s_SCNewOrder TrailOrder;
TrailOrder.OrderQuantity = totalBuyOrderSubmitted - totalExits;
TrailOrder.OrderType = SCT_ORDERTYPE_TRAILING_STOP;
TrailOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;
TrailOrder.Price1 = target1Price - 10 * sc.TickSize;
sc.SellOrder(TrailOrder);

the above works.

I was missing the OrderType

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

Login

Login Page - Create Account