Download MetaTrader 5

Function that returns if the last trade was a win or lose trade

To add comments, please log in or register
Store your source codes in MQL5 Storage. It is secure!
Jhenrique Vissotto
263
Jhenrique Vissotto 2016.08.23 14:30 
I’m looking for a function that returns if the last trade was a win or lose trade. In other words, if the price hit the take profit or the stop loss of the last trade.

If someone decide help me, so, PLEASE, give-me a function that you have sure that work correctly, because I’m not programmer and I have too much difficult with programming… PLEASE…

Thanks a lot!
Muhammad Mudasir
6761
Muhammad Mudasir 2016.08.23 17:09  
string   LastOrderPL() {
   
   string LastOrderStatus;
   double ProfitandLoss=0.00;

   for(int i=OrdersHistoryTotal()-1;i>=0;i--)
  {
   
   
   if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) &&OrderSymbol()==Symbol()){
     
     if(OrderProfit()>ProfitandLoss){
            LastOrderStatus="Last Order Was in Profit";
            Alert(OrderProfit());
            break;}
            
     else if(OrderProfit()<ProfitandLoss){
     Alert(OrderProfit());
            LastOrderStatus="Last Order Was in Loss";
            break;
     }
   }
    
   }
   return(LastOrderStatus);
   }
   
Code is tested and compiled check that
Jhenrique Vissotto
263
Jhenrique Vissotto 2016.08.25 18:06  
Muhammad Mudasir:
Code is tested and compiled check that

Thanks a lot man!!!!! :) 

To add comments, please log in or register