Finding History Data in MT5

 

I am trying to migrate to MT5 and really struggling with HISTORY.

I tried to adopt some code - then gave up and been trying by trial and error.  I have read some of the articles but just somehow don't get it.

MT4 seemed so simple.

If I download the HISTORY CSV I get large report which contains:

POSITIONS Then

ORDERS Then

DEALS Then

OPEN POSITIONS

I'd like to be able to identify from inside an EA a POSITION (from POSITIONS above) I see listed by Ticket Number. 

(Example take the last 5 USDJPY - say - and list them on the screen with PROFIT/LOSS Time OPEN & CLOSE and visualise each with a trendline)

So I pass a TicketNumber to my sub which contains the following.

#include <errordescription.mqh>
#include <Trade\Trade.mqh>
#include <Trade\DealInfo.mqh>
#include <Trade\HistoryOrderInfo.mqh>
  
HistorySelect(0,TimeCurrent());               // get the history//for(uint i=0;i<TotalNumberOfDeals;i++)                                  // go through all the deals   
   if ( HistoryOrderSelect(TicketNumber ) == true)
   {  OrderOpenPrice    = HistoryOrderGetDouble(TicketNumber,ORDER_PRICE_OPEN);
      OrderClosePrice   = HistoryOrderGetDouble(TicketNumber,ORDER_PRICE_CURRENT);
      MySymbol          = HistoryOrderGetString(TicketNumber,ORDER_SYMBOL);
      MyResult          = "MySymbol = "+MySymbol+" TicketNumber = "+IntegerToString(TicketNumber)+
                        " OrderOpenPrice = "+DoubleToString(OrderOpenPrice,5)+" OrderClosePrice = "+DoubleToString(OrderClosePrice,5);
   }

There doesn't seem to be a valid means of finding ORDER_PROFIT say and the I can't find a CLOSE PRICE. 

The Select statement followed by OpenPrice & Symbol appear to be  correct

Any help appreciated

 
Peter Williams:

I am trying to migrate to MT5 and really struggling with HISTORY.


I eventually came up with the following whgich works and maybe useful to someone.

I complete the following for each TicketNumber

//================================GetHistoryDetails START==============================+
void GetHistoryDetails()
{  
   HistorySelect(0,TimeCurrent());    
   {  OrderOpenPrice    = HistoryOrderGetDouble    ( TicketNumber, ORDER_PRICE_OPEN);
      dt_open           = HistoryOrderGetInteger   ( TicketNumber, ORDER_TIME_SETUP);
      MySymbol          = HistoryOrderGetString    ( TicketNumber, ORDER_SYMBOL);
      HistorySelectByPosition(TicketNumber);
      for (int i = 0; i < HistoryDealsTotal(); i++) 
      {
        ulong deal_ticket = HistoryDealGetTicket(i);
        if (HistoryDealGetInteger(deal_ticket, DEAL_ENTRY) == DEAL_ENTRY_OUT) 
        {
           OrderClosePrice = HistoryDealGetDouble  (deal_ticket, DEAL_PRICE);
           OrderProfit     = HistoryDealGetDouble  (deal_ticket, DEAL_PROFIT);
           dt_close        = HistoryDealGetInteger (deal_ticket, DEAL_TIME);
        }
      }
   }
   return;// StrMyResult;     // return the result
}
//==============================GetHistoryDetails END======================================+
Reason: