Set StopLoss and TakeProfit in Price

Created at 27 Mar 2024, 16:02
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!
Maruthu's avatar

Maruthu

Joined 05.03.2024

Set StopLoss and TakeProfit in Price
27 Mar 2024, 16:02


  • In cTrade StopLoss can be set in Pips only
  • We need to calculate Pips difference from Price then set it

PendingOrder order;

double slPrice = Your_SL_Price;

double entryPrice = order.TargetPrice;

double priceDiff = ord.TradeType == TradeType.Buy ?  entryPrice - slPrice : slPrice - entryPrice;

double pipGap = priceDiff / Symbol.PipSize;// How many pips are there in the price difference;

ModifyPendingOrderAsync(ord, ord.TargetPrice, pipGap, order.TakeProfitPips);

 


@Maruthu
Replies

PanagiotisCharalampous
28 Mar 2024, 07:23

Hi there,

It is not clear what your post is about. Can you elaborate?

Best regards,

Panagiotis


@PanagiotisCharalampous

barnettariana75
22 Jul 2024, 10:06 ( Updated at: 13 Aug 2024, 09:05 )

@boxing random I revised your code

PendingOrder order;
double slPrice = Your_SL_Price;
double entryPrice = order.TargetPrice;
double priceDiff = order.TradeType == TradeType.Buy ? entryPrice - slPrice : slPrice - entryPrice;
double pipGap = priceDiff / Symbol.PipSize; // Calculate pip difference

ModifyPendingOrderAsync(order, order.TargetPrice, pipGap, order.TakeProfitPips);


 


@barnettariana75