Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

CHistoryPositionInfo Class - MetaTrader 5 Library - MT4/MT5 Resources

author EAcpu | 2 reads | 0 comments |

The CHstoryPositionInfo class provides easy access to the closing properties.

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

 Class CH historical location information: people object { people :
                    CH historical location information ( blank );
                    ~CH historical location information ( blank );
//--- Method to access protected data ticket ( blank ) constant { return (m_curr_ticket); }
//--- Quick access method for integer position properties datetime open time( blank );
Oolong Time to open MSC( blank );
datetimetimeoff ( blank );
Oolong time to close MSC( blank );
ENUM_POSITION_TYPE position type ( blank );
string type description( blank );
long magic( blank );
long identifier( blank );
ENUM_DEAL_REASON opening reason( blank );
ENUM_DEAL_REASON closing reason ( blank );
//--- Quick access method for dual position properties double volume ( blank );
Double the opening price( blank );
Double stop loss ( blank ) constant ;
Double the take profit ( blank ) constant ;
Double price close( blank );
double committee( blank );
double exchange( blank );
double profit( blank );
//--- Quick access method for string position property string symbol ( blank );
string public comment( blank );
string close comments( blank );
Thin string opening reason description ( blank );
string closure reason description ( blank );
string discount tickets ( const string separator = " " );
//--- Information method string format type ( string &str, constant unit type) constant ;
string formatreason( string &str, const unitreason ) constant ;
//--- Method to select location boolean history selection ( datetime start date, datetime so far);
Integer total number of positions ( blank ) constant ;
Boolean value Select by vote ( constant own vote);
boolean select by index( const integer index);
  };


Here is a sample code showing how to use this class in code

#include //+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
blank start ()
  { //--- Variable to save historical position information CHistoryPositionInfo hist_position; //--- Retrieve the historical records of closing positions within the specified time period if (!hist_position.History selection ( 0 , time current ()))
    {
alert ( "CHistoryPositionInfo::HistorySelect() failed!" );
return ;
    } //--- Now handle closing list integer total = hist_position. Total positions ();
for ( integer i = 0 ; i < total; i++)
    {
//--- Select a position to close by index in the list if (hist_position.SelectByIndex(i))
        {
Oolong ticket = hist_position.Ticket();
Date time time_open = hist_position.TimeOpen();
Mistake time_open_msc = hist_position.TimeOpenMsc();
Date time time_close = hist_position.TimeClose();
Oolong 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( "," );
//--- integer transaction count = total historical transactions (); // integer for the selected position Number of orders = total number of historical orders (); // for the selected position }
    } //--- Print ( "Total number of closed positions=" , historical position. Total number of positions ());
  } //+------------------------------------------------------------------+

Note: When using the methods History Select() and Select by Index(), the job list is sorted by closing time (not by opening time).

This means that the closing history (data rows) are sorted by closing time to help calculate the running balance , correctly.


Attachment download

📎 historypositioninfo.mqh (46.86 KB)

📎 demo_chistorypositioninfo.mq5 (5.4 KB)

📎 export_history_positions_v2.mq5 (17.12 KB)

Source: MQL5 #27683

Verification code Refresh