I don't know what is the problem with stoplevel

 

Hi all,

I am coding an EA (MQL4) and with my strategy I want to use the tightest SL that the broker allows.

For a BUY order :

double stopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL)*Point;
double sl = Bid - stopLevel;

For a SELL order :

double sl = Ask + stopLevel;


I have tested the EA on my live account, most of the time the orders are correctly opened, sometime there are offquotes (there is not a problem, I know it can happens) but sometimes an order is not opened because of an "Invalid S/L or T/P" :

2010.09.06 02:55:04    'XXXXX': order buy 0.01 EURUSD opening at 1.28792 sl: 1.28756 tp: 1.29092 failed [Invalid S/L or T/P]
2010.09.06 02:55:04    'XXXXX': instant order buy 0.01 EURUSD at 1.28792 sl: 1.28756 tp: 1.29092

In the Expert logs tab my EA print some informations for debugging :

2010.09.06 02:55:04    ChrisEA v1.2 EURUSD,M1: Bid=1.28776 Ask=1.28792
2010.09.06 02:55:04    commun EURUSD,M1: Erreur à l'ouverture d'un ordre : 130

You can see it is an error 130 ("Invalid stops") but I don't understand what's the problem :

It is a buy order, stop loss = Bid - stop level = 1.28776 - 0.0002 = 1.28756

And I have 2 orders with this errors and 6 orders OK.

Thank you for your help !

 

Stops are too close, or prices are ill-calculated or unnormalized (or in the open price of a pending order). The attempt can be repeated only if the error occurred due to the price obsolescense. After 5-second (or more) delay, it is necessary to refresh data using the RefreshRates function and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed.

https://docs.mql4.com/trading/errors 

 
Ok I see, thank you for your fast reply. I will try to widen a little the SL or to change the code to retry the opening.
Reason: