Download MetaTrader 5

detect the last order status

To add comments, please log in or register

Hi All, 

Could anybody give me an idea about

how to detect the last running transaction order status

whether it is still running or has been closed(because it reach the TP or SL) ?


where will i start from to reach this result ? 

Many thanks in advance. 


my apologize for my bad english. :)

Osama Shaban
Osama Shaban  

I coded this function several years ago ... It worked perfect for me to detect last closed trade (History) in case the profit was in loss ...

You can change it according to your needs. You just need to do minor changes ... 

void LastClosedTrade(){ 
   int cnt, total; 
   total = OrdersHistoryTotal(); 
   for(cnt=0;cnt<total; cnt++){ 
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNo && OrderProfit()!=0){
         LastOrderType = OrderType(); 
         LastOrderLots = OrderLots(); 
         LastOrderProfit = OrderProfit(); 
To add comments, please log in or register