Invalid stop loss with order send

 

Hello, I am developping an EA and sometimes when I try to buy or send, I get the error message (sometimes, the transaction is OK) :

failed market sell 4.71 #TSLA sl: 42.86 [Invalid stops]

CTrade::OrderSend: market sell 4.71 #TSLA sm: 42.86 [invalid stops]


I understand than my stop loss is wrong but I don't understand why because the point is 0.01 and the difference between the bid and the stop loss is more than 0.01.


This is all information about the transaction:

- bid: 42.43

- stop loss: 42.86

- point: 0.01


This is how I calcultate the stop loss:

stopLoss = bid * (1 + stopLossPercent / 100)


The idea is to have a stop loss calculated in percentage from the bid because it's easier for me.

In the above exemple, the stop loss is at 1 percent from the bid.


Someone can explain me what is wrong please?


Thanks

Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
  • www.mql5.com
Trade Server Return Codes - Codes of Errors and Warnings - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Aurelien Pierre Laval: Someone can explain me what is wrong please?
  1. Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the file.
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

    We can't see your broken code.

  2. We don't even know that you are trying to open a sell order.

Reason: