거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Facebook에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
라이브러리

CHistoryPositionInfo Class - MetaTrader 5용 라이브러리

조회수:
7281
평가:
(20)
게시됨:
2020.01.21 03:26
업데이트됨:
2021.10.24 23:13
\MQL5\Include\ \MQL5\Scripts\
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

CHistoryPositionInfo class provides an easy access to the closed position properties.

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

class CHistoryPositionInfo : public CObject
  {
public:
                     CHistoryPositionInfo(void);
                    ~CHistoryPositionInfo(void);
   //--- methods of access to protected data
   ulong             Ticket(void)           const { return(m_curr_ticket); }
   //--- fast access methods to the integer position properties
   datetime          TimeOpen(void);
   ulong             TimeOpenMsc(void);
   datetime          TimeClose(void);
   ulong             TimeCloseMsc(void);
   ENUM_POSITION_TYPE PositionType(void);
   string            TypeDescription(void);
   long              Magic(void);
   long              Identifier(void);
   ENUM_DEAL_REASON  OpenReason(void);
   ENUM_DEAL_REASON  CloseReason(void);
   //--- fast access methods to the double position properties
   double            Volume(void);
   double            PriceOpen(void);
   double            StopLoss(void) const;
   double            TakeProfit(void) const;
   double            PriceClose(void);
   double            Commission(void);
   double            Swap(void);
   double            Profit(void);
   //--- fast access methods to the string position properties
   string            Symbol(void);
   string            OpenComment(void);
   string            CloseComment(void);
   string            OpenReasonDescription(void);
   string            CloseReasonDescription(void);
   string            DealTickets(const string separator = " ");
   //--- info methods
   string            FormatType(string &str,const uint type) const;
   string            FormatReason(string &str,const uint reason) const;
   //--- methods for select position
   bool              HistorySelect(datetime from_date,datetime to_date);
   int               PositionsTotal(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 <CHistoryPositionInfo.mqh>
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- variable to hold the history position info
   CHistoryPositionInfo hist_position;

//--- Retrieve the history of closed positions for the specified period
   if(!hist_position.HistorySelect(0,TimeCurrent()))
     {
      Alert("CHistoryPositionInfo::HistorySelect() failed!");
      return;
     }

//--- now process the list of closed positions
   int total = hist_position.PositionsTotal();
   for(int i = 0; i < total; i++)
     {
      //--- Select a closed position by its index in the list
      if(hist_position.SelectByIndex(i))
        {
         ulong    ticket            = hist_position.Ticket();
         datetime time_open         = hist_position.TimeOpen();
         ulong    time_open_msc     = hist_position.TimeOpenMsc();
         datetime time_close        = hist_position.TimeClose();
         ulong    time_close_msc    = hist_position.TimeCloseMsc();
         long     type              = hist_position.PositionType();
         string   type_desc         = hist_position.TypeDescription();
         long     magic             = hist_position.Magic();
         long     pos_id            = hist_position.Identifier();
         double   volume            = hist_position.Volume();
         double   price_open        = hist_position.PriceOpen();
         double   price_sl          = hist_position.StopLoss();
         double   price_tp          = hist_position.TakeProfit();
         double   price_close       = hist_position.PriceClose();
         double   commission        = hist_position.Commission();
         double   swap              = hist_position.Swap();
         double   profit            = hist_position.Profit();
         string   symbol            = hist_position.Symbol();
         string   open_comment      = hist_position.OpenComment();
         string   close_comment     = hist_position.CloseComment();
         string   open_reason_desc  = hist_position.OpenReasonDescription();
         string   close_reason_desc = hist_position.CloseReasonDescription();
         string   deal_tickets      = hist_position.DealTickets(",");
         //---
         int      deals_count       = HistoryDealsTotal();   // of the selected position
         int      orders_count      = HistoryOrdersTotal();  // of the selected position
        }
     }
//---
   Print("Total closed positions = ",hist_position.PositionsTotal());
  }
//+------------------------------------------------------------------+


Note: when using the methods HistorySelect() and SelectByIndex(), the list of positions is ordered by time of closing (not by the opening times).

This means the history of closed positions (data rows) is ordered by Close Time to help calculate the running  Balance, correctly.




3D Spiral Quotes 3D Spiral Quotes

Demonstration of Canvas's capabilities using 3D spiral quotes as an example.

Pseudo-Indicator with Asynchronous Multi-Threaded Calculations Demo Pseudo-Indicator with Asynchronous Multi-Threaded Calculations Demo

This is an indicator w/o buffers which demonstrates parallel multi-threaded calculations in chart objects hosting worker expert adviser.

3D Moving Average 3D Moving Average

The first really 3D indicator "Moving Average".

CSetFileReader CSetFileReader

Class to provide simple reading mechanism from MetaTrader set files.