How to get the open, close and profit price of an order from history section in MQL5

To add comments, please log in or register
Jhojan Alberto Tobon Monsalve
292
Jhojan Alberto Tobon Monsalve  

I'm trying to get the open, close prices and the profit of an ORDER in the history section, but I do not know how to achieve this. I'm trying with the following code:

    HistorySelect(0,TimeCurrent());
    int totalDeals = HistoryDealsTotal();
    int totalOrders = HistoryOrdersTotal();
    
    
    int i = 0;
    
    ulong dealTicket = HistoryDealGetTicket(i+1);
    ulong orderTicet = HistoryOrderGetTicket(i);
    double orderProfit = HistoryDealGetDouble(dealTicket,DEAL_PROFIT);
    double orderOpenPrice = HistoryOrderGetDouble(orderTicet,ORDER_PRICE_OPEN);
    double orderClosePrice = HistoryDealGetDouble(dealTicket,DEAL_PRICE);

But the tickets of DEALS and ORDERS are different and I do not know if there is a way to get the  open price of a DEAL or the close price and the profit of an ORDER.

I need to migrate an EA from Mql4 [ OrderProfit(),OrderClosePrice(),OrderOpenPrice()] to Mql5. 

Thanks in advance.

zoster81
7
zoster81  

look this https://www.mql5.com/en/code/19702

and this https://www.mql5.com/en/code/21434

VR Orders History MT5 Lite
VR Orders History MT5 Lite
  • www.mql5.com
VR Orders History MT5 Lite - a script for downloading trading history in the CSV format. The Lite version demonstrates a small part of the source code of the VR Orders History MT5 script. This universal script can run both on hedging and netting accounts. The script divides the report into two stages: The first stage includes existing current...
fxsaber
10289
fxsaber  
Jhojan Alberto Tobon Monsalve:

I need to migrate an EA from Mql4 [ OrderProfit(),OrderClosePrice(),OrderOpenPrice()] to Mql5.

Forum on trading, automated trading systems and testing trading strategies

How to figure out the close price when position ran into stop loss?

fxsaber, 2018.07.10 11:46

#include <MT4Orders.mqh> // https://www.mql5.com/en/code/16006

void OnStart()
{
  const int Total = OrdersHistoryTotal();
  
  for (int i = 0; i < Total; i++)
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
      OrderPrint();  
}
Hosein Daneshnia
232
Hosein Daneshnia  
Jhojan Alberto Tobon Monsalve:

I'm trying to get the open, close prices and the profit of an ORDER in the history section, but I do not know how to achieve this. I'm trying with the following code:

But the tickets of DEALS and ORDERS are different and I do not know if there is a way to get the  open price of a DEAL or the close price and the profit of an ORDER.

I need to migrate an EA from Mql4 [ OrderProfit(),OrderClosePrice(),OrderOpenPrice()] to Mql5. 

Thanks in advance.

hi you can use this one : 


void history_checker()
{
int margines=0;
string ordertyp="NULL";
double prft=0;
for( int TradeCount=OrdersHistoryTotal()-1;TradeCount>=0;TradeCount--)
      {
        if ( OrderSelect(TradeCount,SELECT_BY_POS,MODE_HISTORY))
        {
          if(OrderType()==0)
          ordertyp="BUY";
          else if (OrderType()==1)
          ordertyp="SELL";
          else if (OrderType()>1)
          ordertyp="NULL";
          prft=(OrderSwap()+OrderProfit())-OrderCommission();
          
         //margines:=iBarShift(OrderSymbol(),PERIOD_W1,OrderOpenTime()); 
         //OrderType();    OrderProfit()  ; datetime OrderCloseTime() ;
         if(OrderType()<=1)
         { 
         Print("Order:"+ ordertyp +":"+"Order Profit:"+DoubleToStr(prft,2)+":"+"Order Open Time:"+TimeToStr(OrderOpenTime(),TIME_DATE|TIME_SECONDS)+":"+"Order Close Time:"+TimeToStr(OrderCloseTime(),TIME_DATE|TIME_SECONDS)         
          );
          
          }
      }
     }

To add comments, please log in or register