Set TakeProfit To Zero / open

Created at 24 May 2023, 09:06
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
CT

ctid5696420

Joined 17.02.2023

Set TakeProfit To Zero / open
24 May 2023, 09:06


Hi,

 

I currently have an active position with set values for Stop Loss (SL) and Take Profit (TP). However, I would like to set the Take Profit value to open, meaning that I want to remove the specific TP value and keep it undefined. I am using the cTrader Open API and wondering how I can achieve this.

Although I can successfully update the SL/TP using the ProtoOAAmendPositionSLTPReq method, I haven't been able to find a way to simply open the TP without specifying a value. Can you please assist me in achieving this using the cTrader Open API?

 var message = new ProtoMessage
                        {
                            Payload = new ProtoOAAmendPositionSLTPReq
                            {
                                CtidTraderAccountId = CtidTraderAccountId,
                                PositionId = PositionId,
                                StopLoss = (double)stoploss,
                                TakeProfit = double.NaN,    /////What Value Do I need to Pass Here ??????

                            }.ToByteString(),
                            PayloadType = (int)ProtoOAPayloadType.ProtoOaAmendPositionSltpReq,
                        };
                        return message;

Thank You.


@ctid5696420
Replies

jesustotten735
09 May 2024, 03:57 ( Updated at: 10 May 2024, 03:00 )

Hello @merge fruit, to open the Take Profit (TP) value without specifying a specific value using the cTrader Open API, you can set the TakeProfit field to null or remove it from the request altogether. Here's an example of how you can modify your code:

csharpvar message = new ProtoMessage{   Payload = new ProtoOAAmendPositionSLTPReq   {       CtidTraderAccountId = CtidTraderAccountId,       PositionId = PositionId,       StopLoss = (double)stoploss,       TakeProfit = null, // Set TakeProfit to null or remove the field   }.ToByteString(),   PayloadType = (int)ProtoOAPayloadType.ProtoOaAmendPositionSltpReq,};return message;

@jesustotten735