How Set StopLoss and TakeProfit based on actual price not Pips

Created at 27 Sep 2022, 11:17
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!
HE

HexDex

Joined 21.09.2022

How Set StopLoss and TakeProfit based on actual price not Pips
27 Sep 2022, 11:17


Hello 

 

I am struggling to overcome this issue in my cBot which is setting SL and/or TP for my pending orders based on price, not pips..  Please have a look at the code below(partial code). below code places the pending order correctly but the "slpricesell " is supposed to be the Stoploss price which the code takes it as pips.

 

Any idea what am I missing here?

 

 

          if(selltriggerline > 0 && sell_coun <=0 && sell_order ==0) 
          //place Sell StopLimit order
          {     
                //double _lots = Lot * 100; 
                var _lots = Symbol.QuantityToVolumeInUnits(Lot);
                _sellanddistance = selltriggerline - (Symbol.PipSize * Distance);
                double? slpricesell = (StopLoss   * Symbol.PipSize) + (Distance * Symbol.PipSize)  + selltriggerline;
                double? tppricesell = (TakeProfit * Symbol.PipSize) - (Distance * Symbol.PipSize)  - selltriggerline;
                //Print(slpricesell);
                if(OrderType == 1) {var trs = PlaceStopLimitOrder(TradeType.Sell, SymbolName, _lots ,_sellanddistance ,Slippage, Name,   slpricesell,  tppricesell,null,Name, false,  StopTriggerMethod.Trade, StopTriggerMethod.Trade);                     }
                
                if(OrderType == 2) {var trs = PlaceStopOrder     (TradeType.Sell, SymbolName, _lots ,_sellanddistance ,          Name,   slpricesell,  tppricesell,null,Name, false,  StopTriggerMethod.Trade, StopTriggerMethod.Trade);                      }

          }

 


@HexDex
Replies

PanagiotisCharalampous
27 Sep 2022, 11:41

Hi HexDex,

The API does not offer the option to set the SL and TP in absolute prices, only in pips. If you want set the TP and SL in prices then you need to do this for the opened position.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous