Download MetaTrader 5

Closed Positons Details

To add comments, please log in or register
brunoneveslt
30
brunoneveslt 2012.07.02 20:21 

Hi,


How can I get a list and details about their positions already closed?


Thanks

onewithzachy
2271
onewithzachy 2012.07.03 00:51  
brunoneveslt:

Hi,

How can I get a list and details about their positions already closed?

Thanks

Hi brunoneveslt,

It's in trade function (https://www.mql5.com/en/docs/trading)   with everything that have the word history. for example HistorySelect, HistorySelectByPosition, etc, etc.

:D 

Documentation on MQL5: Trade Functions
  • www.mql5.com
Trade Functions - Documentation on MQL5
johhny6
130
johhny6 2012.07.05 13:01  
brunoneveslt:

Hi,


How can I get a list and details about their positions already closed?


Thanks


this is useful, emails you last close-position trade, basically to get P/L.

call EmailMeHistory whenever you like, in EA or script.

change 3600 to longer if you want more than last hour of trades.

note this shows exit position info only, change for other info.


void EmailMeHistory()
  {
   HistorySelect((TimeCurrent()-3600),TimeCurrent()); // 3600 = last hour, make it longer if you want. 86400 = 1 day
   uint deals=HistoryDealsTotal();
   ulong ticket;
   string dealsymbol="empty";
   string str="";
   uint x=0;
   for(x=deals;x>0;x--)
     {
      if((ticket=HistoryDealGetTicket(x))>0)
        {
         dealsymbol=HistoryDealGetString(ticket,DEAL_SYMBOL);
         if((dealsymbol==_Symbol) && (HistoryDealGetInteger(ticket,DEAL_ENTRY)==DEAL_ENTRY_OUT)) // closed position
           {
            // its relevant, continue
            MqlDateTime dt;
            TimeToStruct(HistoryDealGetInteger(ticket,DEAL_TIME),dt);
            // build string
            StringFormat("+ Relevant history found: %02d:%02d:%02d (%d/%d/%d)\n",dt.hour,dt.min,dt.sec,dt.day,dt.mon,dt.year);
            str+=StringFormat(" P/L: \t %.2f (swap: %.2f)\n Vol: \t %.2f\n Ticket: \t %i / %i / %i\n Swap: \t %.2f\n\n",
                              HistoryDealGetDouble(ticket,DEAL_PROFIT),HistoryDealGetDouble(ticket,DEAL_SWAP),
                              HistoryDealGetDouble(ticket,DEAL_VOLUME),ticket,
                              HistoryDealGetInteger(ticket,DEAL_POSITION_ID),HistoryDealGetInteger(ticket,DEAL_ORDER)
                              );
           }
        }
     }
   if(str!="")
     {
         SendMail("Trade history for"+_Symbol,str);       
     }
  }
To add comments, please log in or register