[MQL5] Invalid stops to buy


Hello, I develop an EA but sometimes, I get the error message:

failed market buy 0.1 BTCEUR sl: 772.10 tp: 795.63 [Invalid stops]
CTrade::OrderSend: market buy 0.10 BTCEUR sl: 772.14 tp: 795.67 [invalid stops]

I try to buy 0.1 BTCEUR and below are all informations I have about the BTCEUR:

ask : 783.89
bid : 783.87
point : 0.01
stopLossValue : 772.10195
takeProfitValue : 795.6280499999999
Minimum size: 0.1 BTCEUR

I understand than the price to buy is 783.89, I put the stop loss at 772.1 (-1.5% from the bid price) and the take profit  at 795.63 (1.5% from the bid price).

The point for the BTCEUR is 0.01 and the symbol trade stops level  at 31.

If I am right, it means than the stop loss and the take profit must be at minimum 0.31 (0.01 * 31) from the bid price.

So, it should be good because I am at 11.77 (783.87 - 772.1) for the stop loss and at 11.76 (795.62 - 783.87) for the take profit.

What is wrong please?

What is missing?

mql5.png  18 kb
Always check for the following before setting SL and TP 
   int stops_level=(int)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);
   int freeze_level=(int)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_FREEZE_LEVEL);
      return false;

      return false;
Aurelien Pierre Laval: If I am right, it means than the stop loss and the take profit must be at minimum 0.31 (0.01 * 31) from the bid price.

And SL/TP (stops) need to be normalized to tick size (not Point) — ND code fails on non-currencies.
          On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 programming forum (2011)

And abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 programming forum (2012)

  • Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on non-currencies. So do it right.
              Trailing Bar Entry EA - MQL4 programming forum (2013)
              Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 programming forum (2012)

    For me, 

    is only when we want to modify a position?

    SYMBOL_TRADE_FREEZE_LEVEL : Distance to freeze trade operations in points

    SYMBOL_TRADE_STOPS_LEVEL : Minimal indention in points from the current close price to place Stop orders

    My bot get a bug for the first order.

    My code works fine for CFDs but not for crypto-currencies, what is the difference?

    I will develop to function to normalize price and lots.