Watch how to download trading robots for free

Interesting script?
So post a link to it -
let others appraise it

You liked the script? Try it in the MetaTrader 5 terminal

Libraries

CPairedDealInfo Class - library for MetaTrader 5

amrali

Views:
538
Rating:
votes: 7
Published:
2019.04.06 23:11
Updated:
2019.04.14 09:09
\MQL5\Include\\MQL5\Scripts\

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_ticket_in; }
   ulong             TicketClose(void)                           const { return m_ticket_out; }
   //--- fast access methods to the integer deal properties
   long              OrderOpen(void) const;
   long              OrderClose(void) const;
   datetime          TimeOpen(void) const;
   datetime          TimeClose(void) const;
   ulong             TimeOpenMsc(void) const;
   ulong             TimeCloseMsc(void) const;
   ENUM_DEAL_TYPE    DealType(void) const;
   string            TypeDescription(void) const;
   long              Magic(void) const;
   long              PositionId(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            PriceClose(void) const;
   double            StopLoss(void) const;
   double            TakeProfit(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;
   //--- method for select deals
   bool              Select(datetime from_date,datetime to_date);
   bool              SelectByIndex(const int index);
   int               Total(void) const;
  };


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

#include <PairedDealInfo.mqh>
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- variable to hold the paired deals info
   CPairedDealInfo trade;

//--- reconstruct trades from the history of deals
   trade.Select(0,TimeCurrent());

//--- 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)==true)
        {
         long     type              = trade.DealType();
         long     magic             = trade.Magic();
         long     pos_id            = trade.PositionId();
         ulong    ticket_open       = trade.TicketOpen();
         ulong    ticket_close      = trade.TicketClose();
         datetime time_open         = trade.TimeOpen();
         datetime time_close        = trade.TimeClose();
         double   volume            = trade.Volume();
         double   price_open        = trade.PriceOpen();
         double   price_close       = trade.PriceClose();
         double   price_sl          = trade.StopLoss();
         double   price_tp          = trade.TakeProfit();
         double   commission        = trade.Commission();
         double   profit            = trade.Profit();
         double   swap              = trade.Swap();
         string   symbol            = trade.Symbol();
         string   type_desc         = trade.TypeDescription();
         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());
  }
//+------------------------------------------------------------------+


Balance Graph HTML Balance Graph HTML

Display interactive HTML graph of the account balance inside the web browser.

Pan PrizMA Sin leverage 72 Pan PrizMA Sin leverage 72

Builds a sliding line with a polynomial of 4 degrees. Extrapolates as a section of a given function with a sinusoid and its axial one. One value is taken from the constructed lines on each bar and a line of extrapolated values is plotted, which does not redraw.

Lavika EURGBP/EURUSD Lavika EURGBP/EURUSD

The Expert Advisor uses four iMA (Moving Average, MA) indicators from two timeframes. Two indicators with averaging periods 1 and 8 are created on the H1 timeframe and two indicators with averaging periods 1 and 8 are also created on the H4 timeframe.

Hull moving average Hull moving average

Hull moving average