Download MetaTrader 5

What happens when stop loss operates

To add comments, please log in or register
Sneck55
110
Sneck55  
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
37697
Trinh Dat  

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

Sneck55
110
Sneck55  
Yes I realise that but how do I make the EA aware of the order being closed by the stop loss?
Aleksei Beliakov
25515
Aleksei Beliakov  
it's a good question buddy by the way you talk about mql4 or mql5?
Stuart Browne
5901
Stuart Browne  
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