Take profit & stop loss implementation with Limit & Stop orders

obaum1@gmail.com's avatar

obaum1@gmail.com since: 06 Jun 2017;

  05 Oct 2017, 13:05
Take profit & stop loss implementation with Limit & Stop orders

Hey Guys :)

I saw in this post(/forum/fix-api/11377?page=1) that you can not specify the stop loss and take profit with FIX API.

" Essentially a SL and a TP are just a stop order and a limit order associated to a position with the same volume,
but in the opposite direction. SL and TP are more of an interface feature that allows you to keep pending orders associated
with a position, rather than a specific trading instruction. 
Therefore we do not plan to make this feature a parts of FIX API. 
Instead, it is advised to implement SL and TP on your side by opening a stop loss order and,
a limit order linked to a position with the same volume and the opposite direction. " 

Can you please explain further about how to implement take profit & stop loss with Limit & Stop orders ?

Example: Buy, EURUSD, 1,000, EnterPrice 1.17852

*I would like to close in 10 pips TargetPrice: 1.17952

Which steps I need to take to do it right?

-- Please consider the environment. We don't have a replacement yet.
obaum1@gmail.com's avatar

obaum1@gmail.com since: 06 Jun 2017;

  05 Oct 2017, 23:23

Hey :)

If I understand right, If I have for the following EXAMPLE: (Buy, EURUSD, 1,000, EnterPrice 1.17852) and I want
To associated Limit Order & Stop Order I need to do the following:

TakeProft Steps:
1) Set Buy, EURUSD, 1,000, EnterPrice: 1.17852 
2) Set Limit Order for Sell, 1,000, TargetPrice: 1.17952
3) When target price trigged, I have two positions that hold the profit of 10 pips


StopLoss Steps:
1) Set Buy, EURUSD, 1,000, EnterPrice: 1.17852 
2) Set Stop Order for Sell, 1,000, TargetPrice: 1.17752
3) When target price trigged, I have two positions that hold the loss of 10 pips

So far I'm good?

If this is case it seems that the cost in commissions is higher then using 
The Connect API which holds the option for setting position TakeProfit & StopLoss.

-- Please consider the environment. We don't have a replacement yet.
PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  06 Oct 2017, 09:26

Hi obaum1@gmail.com,

Can you please clarify what do you mean when you say that you have two positions? When you enter the marker with your market order at 1.17852, a position is created. Which is the second one? 

Also why do you say that commissions are higher?

In general the steps of your example are correct. You should also remember when an SL/TP order is executed to cancel the other one.

Best Regards,

Panagiotis

Head of Community Management at cTrader
obaum1@gmail.com's avatar

obaum1@gmail.com since: 06 Jun 2017;

  07 Oct 2017, 01:08

Hey :)

Thanks for the reply!!

If I understood right. I can't set TakeProfit and StopLoss via the FIX API.

To overcome this problem I need to work with Limit Order & Stop Order.

EXAMPLE:

  • 1) I have the following position running:
    • 1) (EURUSD, Buy, 1,000, EnterPrice 1.17852)
  • 2) I want to set TakeProfit of 10 pips for that position
  • 3) I set LimitOrder with (Sell, 1,000, TargetPrice: 1.17952)
  • 4) when the target price is triggered now I have two running positions 
    • 1) (EURUSD, Buy, 1,000, EnterPrice 1.17852)
      • 2) (Sell, 1,000, EnterPrice: 1.17952)
  • 5) secondPosition - firstPosition = 10 pips

Each trade commission is around 0.08 -> so I payed 0.16 in commission because I opened two positions.

If I open my position via Connect API I can set TakeProfit & StopLoss and the position will "close it self" and I paid 0.08

If this is correct, so maybe I can create trades with the FIX API and modify the position TakeProfit & StopLoss with Connect API?

Thanks!!!

-- Please consider the environment. We don't have a replacement yet.
PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  09 Oct 2017, 09:21

Hi obaum1@gmail.com,

when the target price is triggered now I have two running positions 

This is not true. If you use tag 721, your order will pe placed to the specified position, hence in this case it will close the position instead of opening a new one.

Each  trade commission is around 0.08 -> so I payed 0.16 in commission because I opened two positions.

If I open my position via Connect API I can set TakeProfit & StopLoss and the position will "close it self" and I paid 0.08

Commissions are per side (open/close). You will pay 0.08 when you open a position and 0.08 when you close a position. So in both cases you will pay 0.16. 

Best Regards,

Panagiotis

Head of Community Management at cTrader
obaum1@gmail.com's avatar

obaum1@gmail.com since: 06 Jun 2017;

  09 Oct 2017, 20:00

Hey Panagiotis,

OK, the tag 721 was super helpful!!!

And thanks in general!!! :)

-- Please consider the environment. We don't have a replacement yet.

viniciusfre since: 28 Dec 2018;

  20 Mar 2019, 15:05

Hi,

I am trying to modify a position for to set Take profit or Stop loss as per Solid Snake steps, but it is not working.

So I am sending first a buy market message:

    side = 1(BUY)
    _orderType = 1(OrdType_MARKET)
    _symbol = 1 (EURUSD)
    _orderQty = 1000
    _timeInForce = 3(IMMEDIATE_OR_CANCEL)
    _price = 0
    _stopPx = 0

And then I send a take profit buy message:

    side = 2(SELL)
    _orderType = 2(OrdType_LIMIT)
    _symbol = 1 (EURUSD)
    _orderQty = 1000
    _timeInForce = 1(GOOD_TILL_CANCEL)
    _price = AvgPx + 0.00032 (32 points gain)
    _stopPx = 0
    PosMaintRptID = X (Value received in ExecutionReport)

 Instead mofify the buy position, the server is creating a pending order. What is wrong?

PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  20 Mar 2019, 15:13

Hi viniciusfre,

There is nothing wrong, this is how it should be done. As described above, you cannot set SL and TP via FIX API. Therefore you need to manage orders of the opposite direction. Requoting from the first post

" Essentially a SL and a TP are just a stop order and a limit order associated to a position with the same volume, but in the opposite direction. SL and TP are more of an interface feature that allows you to keep pending orders associated with a position, rather than a specific trading instruction.  Therefore we do not plan to make this feature a parts of FIX API.  Instead, it is advised to implement SL and TP on your side by opening a stop loss order and, a limit order linked to a position with the same volume and the opposite direction. "

You will need to handle these orders independently.

Best Regards,

Panagiotis

Head of Community Management at cTrader

khezrian since: 24 Feb 2022;

  24 Feb 2022, 14:11
Automatic cancellation of Pending Orders Limit and Stop

Hi,

Based on the issues raised in this post, and since T/P and S/L cannot be determined directly through the FIX API, it should be done as Limit and Stop by creating a new order contrary to the original position.

These Limit and Stop orders are placed in the order list as Pending Order.


PositionID value (or tag 721) is sent when registering Limit and Stop orders.


We have two problems:

1- If the main position is closed by any of the Limit or Stop orders, the other order will remain in the Pending Order list.
Question: How can this be done automatically? , Ie if the main position is closed by Pending Order Limit, Pending Order Stop is automatically deleted (deleted or closed) and vice versa, if the main position is closed by Pending Order Stop, Pending Order Limit is automatically deleted (deleted) Or be closed).

2- If the main position is closed manually through any platform (for example, cTrader), the two orders created Limit and Stop will remain in the order list.


Since we send tag 721, which is PositionID, when creating Limit and Stop orders, we expect these Pending Orders to be removed as the main position closes.


I know that I can report the status of the position using (MsgType(35)=AP) and I also know that I can cancel an order using (MsgType(35)=F).

I'm looking for a solution, after applying one of the Pending Order Limit or Stop, Another Pending Order is automatically canceled.

Please advise what should be done in this regard.

PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  24 Feb 2022, 14:18

Hi khezrian,

There is no automatic solution for this. You need to handle these scenarios yourself.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Head of Community Management at cTrader