I am coding an algorithmic trading robot and how can I check if the order hit SL on MQL4?
Asked
Active
Viewed 1,478 times
2 Answers
1
The most robust method is to record then track the trade using its OrderTicket(). Track this until the trade is closed (using OrderCloseTime() to determine when closed). You can then retrieve the OrderClosePrice() and check it against the OrderStopLoss().

PaulB
- 1,262
- 1
- 6
- 17
-
But I'm getting a weird error. It gives me the closing price even though I asked for the order open price. `if(OrderSelect(Ticket[0],SELECT_BY_TICKET) == true) { Print("Order Open Price = " + OrderOpenPrice()); Print("Order Close Price = " + OrderClosePrice()); Print("Order Stop Loss Price = " + OrderStopLoss()); }` Where am i doing wrong? – NeoOne Jan 01 '22 at 21:34
-
This is a separate question to the one asked. I would suggest marking this answer as accepted and posting a new question with your full code. – PaulB Jan 03 '22 at 09:44
0
For MQL5
If trade hit stoploss or target then it will close automatically You just need to check position of that symbol.
if(!PositionSelect(_Symbol))
{
// trade is closed, now you can take new entry of that symbol.
}

Mahesh Mahadar
- 21
- 1
- 6
-
1The question is specifically relating to MQL4. MQL5 is a different programming language and your answer therefore does not address the question. – PaulB Jul 24 '22 at 10:23