please,will someone have better way to do this -->Search last closed price, if last trade was a winning one

 
sometime last closed trade wasn\'t found??????

bool GetLastCloseTradeProfit(double &lastClosedPrice, double &lastClosedProfit)
{
   datetime lastClosedTime = 0;
   lastClosedProfit=0.0;

   //-- Loop history orders
   for(int pos=OrdersHistoryTotal() - 1;pos >= 0; pos--)
   {
      if(OrderSelect(pos,SELECT_BY_POS,MODE_HISTORY)==false) continue;
      
      if(OrderMagicNumber()==Magic && OrderSymbol()==Symbol() &&
         (OrderType()==OP_BUY || OrderType()==OP_SELL) &&
         OrderCloseTime() > lastClosedTime
         )
      {
         lastClosedTime = OrderCloseTime();
         lastClosedPrice = OrderClosePrice();
         lastClosedProfit = OrderProfit();
      }
   }
   bool winner=lastClosedProfit>0.0;

   //-- Check results
   if(lastClosedTime==0)
   {
      Print("Error last closed trade wasn\'t found, an unkonwn error occured.");
      return(false);
   }
   else
      return(winner);
}
 
riskoff:
sometime last closed trade wasn\'t found??????


Check terminal ==>> Account History ==>> Profit

right click on profit

choose All History to display

then try again, might be you had selected last month

 
thank you i will try
Reason: