how to round TP and SL to fixed number of decimals

Created at 15 Feb 2017, 11:33
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!
BE

bernd

Joined 15.02.2017

how to round TP and SL to fixed number of decimals
15 Feb 2017, 11:33


How can I round my TP and SL targets when I send an order to a certain number of decimals depending on the currency pair? I had an order rejected as per log below because of the long decimals on TP and SL. 

Limit order to Buy NZD 84k NZDJPY (Price: 81.903, SL: 48.1499999999997, TP: 6.34999999999997) is REJECTED with error "INVALID_REQUEST"

For example for NZDJPY I want to round TP and SL to 3 decimals. 

Thanks


@bernd
Replies

mindbreaker
15 Feb 2017, 12:13

RE:

bernd said:

How can I round my TP and SL targets when I send an order to a certain number of decimals depending on the currency pair? I had an order rejected as per log below because of the long decimals on TP and SL. 

Limit order to Buy NZD 84k NZDJPY (Price: 81.903, SL: 48.1499999999997, TP: 6.34999999999997) is REJECTED with error "INVALID_REQUEST"

For example for NZDJPY I want to round TP and SL to 3 decimals. 

Thanks

Search in google: C# round

and first pahe from microsoft show what you need (its only C# )

      Console.WriteLine(Math.Round(decValue, 2));
      Console.WriteLine(Math.Round(decValue, 2, MidpointRounding.AwayFromZero));

 


@mindbreaker

mindbreaker
15 Feb 2017, 12:20

API guide:

/api/guides/trading_api#el6

I think SL and TP is in Pips

/api/reference/robot/placelimitorder

public TradeResult PlaceLimitOrder(TradeType tradeType, Symbol symbol, long volume, double targetPrice, string label, double? stopLossPips, double? takeProfitPips)

@mindbreaker

mindbreaker
15 Feb 2017, 12:24

// SL 50 Pips  TP 200 Pips
PlaceStopOrder(TradeType.Buy, Symbol, Volume, Symbol.Bid + (75 * Symbol.PipSize), label, SL, TP);

 


@mindbreaker

mindbreaker
15 Feb 2017, 12:26

See my cBots examples for help:

https://github.com/breakermind/cAlgoRobotsIndicators


@mindbreaker