Try this:
Stringo provided this code to find last closed trade in another thread.
int last_trade=HistoryTotal(); if(last_trade>0) { if(OrderSelect(last_trade-1,SELECT_BY_POS,MODE_HISTORY)==true) { Print("Last trade ticket ",OrderTicket()," op ",OrderType(), " time ",TimeToStr(OrderCloseTime())," price ",OrderClosePrice()); } }
You could change to this:
int last_trade=HistoryTotal(); if(last_trade>0) { if(OrderSelect(last_trade-1,SELECT_BY_POS,MODE_HISTORY)==true) { if(OrderSymbol()==Symbol() && OrderClosePrice()==OrderStopLoss()) { Print("Last closed order was OrderType = ",OrderType()," Time = ",TimeToStr(OrderCloseTime())," close at StopLoss ",OrderClosePrice()); } } }you can replace OrderStopLoss() with OrderTakeProfit() for when order closes at takeprofit.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello,
I'm working with an ea, and I need to know if the last trade closed for stop loss.
How can I know it?
Thanks.