Find latest order in account history

 

Have problem where I want EA to find data from latest closed order in account history that has special comment.

I do not know mql language so good and have problem to figure out logic how to solve this problem 

 

//-- Information from history orders

int      hst,
         hstAll=OrdersHistoryTotal(),
         hstType,
         hstTicket,
         hstCloseTime,
         hstOpenTime,
         hstSellOrders;
double   hstClosePrice,
         hstOpenPrice,
         hstProfit,
         hstStopLoss,
         hstTakeProfit;
string   OrderName;

   for(hst=0;hst<hstAll;hst++)
   {
      if(OrderSelect(hst,SELECT_BY_POS,MODE_HISTORY)==false)

      {
      Alert("Access to history failed with error ",GetLastError());
      }
         if(comment=="Sell[tp]" || comment=="Sell[sl]")
         {
         hstType=OrderType();
         hstTicket=OrderTicket();
         hstCloseTime=OrderCloseTime();
         hstOpenTime=OrderOpenTime();
         hstClosePrice=OrderClosePrice();         
         hstOpenPrice=OrderOpenPrice();
         hstProfit=OrderProfit();
         hstStopLoss=OrderStopLoss();
         hstTakeProfit=OrderTakeProfit();
         hstSellOrders=OrdersHistoryTotal();
         }
   } 
 
elanin: I want EA to find data from latest closed order in account history that has special comment.

  1. For large amounts of code, attach it
  2. https://www.mql5.com/en/forum/139121
  3. Comments can be overwritten by brokers which is what you're looking for. Other brokers do NOT modify the comment.
 
elanin:

Have problem where I want EA to find data from latest closed order in account history that has special comment.

I do not know mql language so good and have problem to figure out logic how to solve this problem 

 

<CODE REMOVED>

Please edit your post . . . 


Please use this to post code . . . it makes it easier to read.

 

Found some more information in very good post about loops https://www.mql5.com/en/forum/139654 and keyword from for me was to use continue; to loop down/up (not sure yet:)) account history until located needed information

 

//-- Information from history orders
int      hst,
         hstType,
         hstTicket,
         hstCloseTime,
         hstOpenTime,
         hstOrder,
         check;
double   hstClosePrice,
         hstOpenPrice,
         hstProfit,
         hstStopLoss,
         hstTakeProfit;
string   OrderName;
   for(hst=0;hst<hstTotal;hst++)
   {
      if(OrderSelect(hst,SELECT_BY_POS,MODE_HISTORY)==false)
      {
      Alert("Access to history failed with error ",GetLastError());
      }
         if(OrderSymbol()==Symbol())
         {  
            for(hstOrder=0;hstOrder<hstTotal;hstOrder++)
               if(!OrderSelect(hstOrder,SELECT_BY_POS,MODE_HISTORY)==true)continue;
               if( OrderComment()=="Sell[tp]"
               || OrderComment()=="Sell[sl]")
         check=0;
         hstType=OrderType();
         hstTicket=OrderTicket();
         hstCloseTime=OrderCloseTime();
         hstOpenTime=OrderOpenTime();
         hstClosePrice=OrderClosePrice();         
         hstOpenPrice=OrderOpenPrice();
         hstProfit=OrderProfit();
         hstStopLoss=OrderStopLoss();
         hstTakeProfit=OrderTakeProfit();
         }
   }

 

Anyway this mystery is solved for me and now up to the next looping mystery..   

Reason: