Randomly Invalid S/L

 

Hi

I got some problem on setting the S/L.

The EA seems running good, but it got the error message sometime. 

Below is the example, position with the same S/L level is opened after 4 second of the Error message.

Can anyone know what happen?


Thanks 

 
Not without seeing the relevant code! 
 

Code is something like below:


extern double TakeProfit = 80;

extern double Stoploss = 50;

double point = Point();

   double SSL = Ask-((Stoploss)*point*1);

   double TL = Ask + (TakeProfit*point*1);


   int Ticket = OrderSend(symb,OP_BUY,Lots,Ask,2,SSL,TL,"TESTING");

 

You will close your buy order at the Bid, but you are calculating your SL and TP relative to the Ask. 

So you could be violating the stop level for the symbol.

This is a useful reference 
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
  • book.mql4.com
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
 
honest_knave:

You will close your buy order at the Bid, but you are calculating your SL and TP relative to the Ask. 

So you could be violating the stop level for the symbol.

This is a useful reference 


Hey, thnaks for above.


But I dont really understand Bid-SL ≥ StopLevel

what is that SL and StopLevel?

 
MT4Billy:


Hey, thnaks for above.


But I dont really understand Bid-SL ≥ StopLevel

what is that SL and StopLevel?


To modify the code, should I just change to below for the stoploss

   double SSL = Bid-((Stoploss)*point*1);

 
MT4Billy:

But I dont really understand Bid-SL ≥ StopLevel

what is that SL and StopLevel?


When you subtract the the stop loss (SL) from the Bid price, the result (in points) must be greater than the stops level.

The stops level is set by your broker, and it could be different on each symbol.

Sometimes it is 0 (although that can mean 2 things). You have to check.

You can see it by pressing CTRL + U and finding your symbol:



Or you can check it in code:

SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);


MT4Billy:


To modify the code, should I just change to below for the stoploss

   double SSL = Bid-((Stoploss)*point*1);


You can try. It has more chance of exceeding the stops level. But no guarantee. It is better to check the value of the stops level than to guess.

Reason: