Download MetaTrader 5
To add comments, please log in or register
Download MQL5 library codes via MetaTrader. It is convenient!
Sneck55
100
Sneck55 2015.04.20 11:36 
Hello, how should I make my EA aware that a stop loss has occurred please? At the moment, when this happens, a lot of errors occur because the program doesn't know the position has been closed automatically. Thank you.
Trinh Dat
36695
Trinh Dat 2015.04.20 18:25  

when orders hit stoploss, then orders closed with comment: [sl]

Sneck55
100
Sneck55 2015.04.20 18:48  
Yes I realise that but how do I make the EA aware of the order being closed by the stop loss?
Aleksei Beliakov
22835
Aleksei Beliakov 2015.04.20 19:37  
it's a good question buddy by the way you talk about mql4 or mql5?
Stuart Browne
5720
Stuart Browne 2015.04.21 00:01  
Sneck55:
Yes I realise that but how do I make the EA aware of the order being closed by the stop loss?

There's a  number of different ways you can do it and it's really going to depend on the logic of your code and also if it's mql4 or 5. Some quick suggestions:

  • Don't set a hard stop (order SL). Control the stop in your code
  • Hold open order tickets in a variable (struct, array etc) then check to see if they're still open
  • Select and analyze closed orders from the pool using MODE_HISTORY
  • And more....

Hope that gets you started

Cheers 

/
To add comments, please log in or register