Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

MetaTrader 5 Libraries | CPairedDealInfo Class

MetaTrader Experts, Indicators, Scripts and Libraries

CPairedDealInfo is a class to reconstruct closed trades (paired in/out deals) from history sorted by close time.

The class has a similar interface to CDealInfo class of the standard library.

class CPairedDealInfo : public CObject    {  public:                       CPairedDealInfo(void);                      ~CPairedDealInfo(void);     //--- methods of access to protected data     ulong             TicketOpen(void)       const { return(m_curr_ticket_in); }     ulong             TicketClose(void)      const { return(m_curr_ticket_out); }     //--- fast access methods to the integer deal properties     datetime          TimeOpen(void) const;     ulong             TimeOpenMsc(void) const;     datetime          TimeClose(void) const;     ulong             TimeCloseMsc(void) const;     ENUM_DEAL_TYPE    DealType(void) const;     string            TypeDescription(void) const;     long              Magic(void) const;     long              PositionId(void) const;     long              OrderOpen(void) const;     long              OrderClose(void) const;     ENUM_DEAL_REASON  OpenReason(void) const;     ENUM_DEAL_REASON  CloseReason(void) const;     //--- fast access methods to the double deal properties     double            Volume(void) const;     double            PriceOpen(void) const;     double            StopLoss(void) const;     double            TakeProfit(void) const;     double            PriceClose(void) const;     double            Commission(void) const;     double            Swap(void) const;     double            Profit(void) const;     //--- fast access methods to the string deal properties     string            Symbol(void) const;     string            OpenComment(void) const;     string            CloseComment(void) const;     string            OpenReasonDescription(void) const;     string            CloseReasonDescription(void) const;     //--- info methods     string            FormatAction(string &str,const uint action) const;     string            FormatReason(string &str,const uint reason) const;     //--- method for select deals     bool              HistorySelect(datetime from_date,datetime to_date);     int               Total(void) const;     bool              SelectByTicket(const ulong ticket);     bool              SelectByIndex(const int index);    };  

Here is a sample code showing how to use the class in your code

#include <CPairedDealInfo.mqh>  //+------------------------------------------------------------------+  //|                                                                  |  //+------------------------------------------------------------------+  void OnStart()    {  //--- variable to hold the paired deals info     CPairedDealInfo trade;    //--- Reconstruct trades from the history of deals     if(!trade.HistorySelect(0,TimeCurrent()))       {        Alert("CPairedDealInfo::HistorySelect() failed!");        return;       }    //--- now process the list of closed trades     int total = trade.Total();     for(int i = 0; i < total; i++)       {        //--- Select a trade by its position in the list        if(trade.SelectByIndex(i))          {           ulong    ticket_open       = trade.TicketOpen();           ulong    ticket_close      = trade.TicketClose();           datetime time_open         = trade.TimeOpen();           ulong    time_open_msc     = trade.TimeOpenMsc();           datetime time_close        = trade.TimeClose();           ulong    time_close_msc    = trade.TimeCloseMsc();           long     type              = trade.DealType();           string   type_desc         = trade.TypeDescription();           long     magic             = trade.Magic();           long     pos_id            = trade.PositionId();           long     order_open        = trade.OrderOpen();           long     order_close       = trade.OrderClose();           double   volume            = trade.Volume();           double   price_open        = trade.PriceOpen();           double   price_sl          = trade.StopLoss();           double   price_tp          = trade.TakeProfit();           double   price_close       = trade.PriceClose();           double   commission        = trade.Commission();           double   swap              = trade.Swap();           double   profit            = trade.Profit();           string   symbol            = trade.Symbol();           string   open_comment      = trade.OpenComment();           string   close_comment     = trade.CloseComment();           string   open_reason_desc  = trade.OpenReasonDescription();           string   close_reason_desc = trade.CloseReasonDescription();          }       }  //---     Print("Total closed trades = ",trade.Total());    }  //+------------------------------------------------------------------+  
25200