MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal

Automated Trading and Strategy Testing Forum

How to Export Quotes from МetaTrader 5 to .NET Applications Using WCF Services How to Export Quotes from МetaTrader 5 to .NET Applications... TTMM Time To Make MoneyTTMM Time To Make Money Try product
TTMM Time To Make Money
Author: Aktiniy
Screenshot
GBPUSD, M30
Demo
MQL5 Wizard - Trade Signals Based on Bullish Harami/Bearish Harami + CCI Expert Advisor
MQL5 Wizard - Trade Signals Based on Bullish Harami/Bearish Harami + CCI
Author: MetaQuotes
Subscribe to signal
AAA1361306
45.73%, 14 520.25 USD

// 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
954
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 (http://www.mql5.com/en/docs/trading)   with everything that have the word history. for example HistorySelect, HistorySelectByPosition, etc, etc.

:D 

johhny6
81
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