API Support Forum
OEC API > API Support > Placing Trailing Stop Order
Author Topic: Placing Trailing Stop Order
(6 messages, Page 1 of 1)
Moderators: VPfau
RAnde
Posts: 20
Joined: Sep 05, 2017


Posted: Oct 31, 2017 @ 05:31 AM             Msg. 1 of 6
I have tried to place a Trailing Stop Order. But I got an exception "Invalid order part: ExtendedData" from OrderDraft.SendOrder. I see that I have to use the method "OrderDraft.SetTSData" to set values for properties "Reference" and "Delta".

#1 - Would you please explain how these properties is used in the Trailing Stop order process?

In my application, the Trailing Stop order has a property that is used for the trailing stop distance. The system will calculate the stop price of order based on the last trade price of symbol and that trailing stop distance.
E.g: If I place a trailing stop order for ESZ7, the currency trade price is 50. And I put the trailing stop distance is 5. So the trailing stop price will be 45.

#2 - What properties of OrderDraft should I pass the trailing stop distance to? Is that OrderDraft.Price, Reference or Delta?

I'm using your API in my application. And I'm getting stuck with Trailing Stop order. I didn't see any information that resolve my problem in your documentation. Please answer my question.
ETrifonov
Posts: 63
Joined:


Posted: Oct 31, 2017 @ 02:50 PM             Msg. 2 of 6
Hello RAnde,

#1 Depending on order side (buy or sell), order will be modified to (+-Delta) price on market price become outside of (Reference +- Delta).

#2 You send Trailing Stop order next way:


var draft = OECClient.Global.CreateDraft();
var contract = OECClient.Global.Contracts["ESZ7"];

draft.Quantity = 1;
draft.Contract = contract;
draft.Side = OrderSide.Buy;
draft.Type = OrderType.TrailingStopLoss;
draft.Account = OECClient.Global.Accounts["TestAccount001"];

// stop price should be greater than last price for ‘buy’ order
draft.Price = contract.CurrentPrice.BidPrice + contract.TickSize * 2;

// delta, should be equal or more than 0
var delta = contract.TickSize;

// Trailing stop orders must be send with delta value diminished by one tick
draft.SetTSData(contract.CurrentPrice.LastPrice, Math.Max(0, delta - contract.TickSize));
OECClient.Global.SendOrder(draft);
Evgeny
RAnde
Posts: 20
Joined: Sep 05, 2017


Posted: Oct 31, 2017 @ 09:41 PM             Msg. 3 of 6
Hi ETrifonov

Thank you very much for replying my question. There is some points that I don't understand in your answer yet.

#1 Depending on order side (buy or sell), order will be modified to (+-Delta) price on market price become outside of (Reference +- Delta)

It means that the Trailing Stop Price of order will be modified by (+/-) Delta when market price becomes outside of (Reference +- Delta).

#1 - Is my understanding correct?

#1.1 - If so, in this case, Delta is the trailing stop distance. And depending on Delta and the current market price, system can calculate the trailing stop price. So why we have to input OrderDraft.Price here?

#1.2 - If my understanding is correct, that Delta is the trailing stop distance, so why is Delta set to 0 in your example? The trailing stop distance (Delta) is 0, so the trailing stop price cannot be modified by it. Right?
Edited by RAnde on Oct 31, 2017 09:41 PM
ETrifonov
Posts: 63
Joined:


Posted: Nov 01, 2017 @ 09:58 AM             Msg. 4 of 6
Hi RAnde,

#1 Yes, your understanding correct, but with remarks below.

#1.2 This because of minimal distance - one contract.TickSize.
Delta will be used to calculate distance.
For provided sample distance will be (Delta + contract.TickSize).
And Trailing Stop Price will be modified by (+/-) Distance when market price becomes outside of (Reference +/- Distance).
Sorry for confusing you.
Evgeny
RAnde
Posts: 20
Joined: Sep 05, 2017


Posted: Nov 02, 2017 @ 01:52 AM             Msg. 5 of 6
Hi ETrifonov

I understood about Reference and Delta. But I still don't understand about OrderDraft.Price.
According to your answer, Trailing Stop order can work well with Reference and Delta.
Why does it need OrderDraft.Price here? What is OrderDraft.Price used for?

And thank you one again for helping me.
ETrifonov
Posts: 63
Joined:


Posted: Nov 02, 2017 @ 07:07 AM             Msg. 6 of 6
OrderDraft.Price is Stop Price.
When market hit this price, order will be modified to Market Order.
Evgeny