API Support Forum
OEC API > API Support > Trailing stop
Author Topic: Trailing stop
(10 messages, Page 1 of 1)
Moderators: VPfau
AAlan
Posts: 13
Joined: Jun 01, 2010


Posted: Jun 08, 2011 @ 05:57 PM             Msg. 1 of 10
Hi,

Are there any examples on how to submit an trailing stop order via the API. I tried to put in different paramter but I still cannot submit a valid trailing stop order via the API.

Thanks.

Alan Chau
THarnett81
Posts: 78
Joined: Jan 13, 2011


Posted: Jun 09, 2011 @ 01:31 PM             Msg. 2 of 10
We're also interested in the mechanics of how to do this.

I found a method in the OrderDraft class to SetTSData. So is it right to set OrderType to TrailingStopLoss and then SetTSData to the desired Reference and Delta? Please also explain what the Reference and Delta prices specifically are.

Thank you.
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Jun 10, 2011 @ 10:16 AM             Msg. 3 of 10
Unfortunately, we have no example for Trailing Stop.

To create trailing stop order, you need to call http://www.openecry.com/api/api/OEC.API.OrderDraft.SetTSData.html to setup reference price and delta value (price threshold). Trailing stop logic uses Reference price as a base line when to start trailing of Stop price

Victor Vins
Lead Software Developer
AAlan
Posts: 13
Joined: Jun 01, 2010


Posted: Jun 10, 2011 @ 05:29 PM             Msg. 4 of 10
Victor,

Thanks for the reply. I have sent the following order to trade the ESM1 in the demo account.

Coditional order
- Buy ESM1 at 1273.5
- Sell ESM1
draft.SetTSData(1275, 0)
draft price = 1

The buy order have been filled and the Sell order is in a working state

The market price of ESM1 moved from 1273.5 to 1278 and then reverse to 1269.

The trailing stop order didn't kick in. The system just modify it from TrStop 1.0 to TrStop 5.0 and reference price remain at 1275. Delta 0.25

Actually, I don't understand what is reference price and delta value. In my example, I think that the reference price at 1275 means that the system starts to trigger the trailing stop with trigger amount of 1. However, it seems that my understanding is incorrect.

Can you help us understand why the system behaves in this way? I thought that the system should execute my trailing stop order but it doesn't work.
p.s. The order# of the trailing stop order in the demo system is 62705122.

Thanks.

Alan Chau
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Jun 13, 2011 @ 03:06 PM             Msg. 5 of 10
Alan,

in your example, trigger price for starting of traling logic will be 1275 (reference price), trigger amount will be one tick size of ESM1 (the first value after Delta value, zero in your example), starting execution price that will be moved by trailing logic is 1 (Draft.Price).

The order's execution price will be adjusted if the current reference market price is better then the previous one and their difference exceeds Delta. Unfortunately, we don't send updated reference price to client and you cannot see clearly how it is working.
AAlan
Posts: 13
Joined: Jun 01, 2010


Posted: Jun 13, 2011 @ 06:28 PM             Msg. 6 of 10
Hi Victor,

Thanks for your explanation. It seems that my understanding on reference price is correct. If that is the case, it seems that the trailing stop order doesn't work when I place it via API. As I stated in my message, the ES price went up and then went down on that night. The ES price should have exceeded the reference price and thus triggered the traling stop. The ES price retraced more than one point and thus it should fire the trailing sell stop to close my long position.

If I look into the order log, it seems that the system just keep on modifying the trailing amount; from 1 to 4 points. Did I miss anything? Is it possible for you to look into my provided order number to see what happen? I may try again in the coming trading session. I hope that I can provide further informaton to you.

Alan Chau
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Jun 13, 2011 @ 07:45 PM             Msg. 7 of 10
Alan, I checked your order. I think you used Draft.Price of sell order incorrectly - the price ( = 1.00 initially in your example) trailed as expected, but was very far from the market. Please try the same example, but set Draft.Price closer to the current market price.


Victor Vins
Lead Software Developer

Edited by VictorV on Jun 13, 2011 at 19:46:10
AAlan
Posts: 13
Joined: Jun 01, 2010


Posted: Jun 14, 2011 @ 02:27 PM             Msg. 8 of 10
Victor,

Thanks for your information. I finally understand the whole picture.
BTW, what is the difference of function call draft.SetEquityTSData? It seems that it is for stock. Can I use the SetTSData for stock, future and forex?

When the system modify a trailing stop order, are there any modify order event? We are dispalying the trailing stop on a DOM and it will be nice if we can update the position of the trailing stop when it is updated on the server.

Thx.

Alan Chau
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Jun 15, 2011 @ 08:11 AM             Msg. 9 of 10
Alan, SetTSData can be used for futures only, SetEquityTSData - for stocks only. OEC doesn't support trailing stops for Forex contracts.

Victor Vins
Lead Software Developer
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Jun 15, 2011 @ 08:14 AM             Msg. 10 of 10
About modify events - right, OECAPI will raise OnCommandUpdated on every modification.

Victor Vins
Lead Software Developer