Download MetaTrader 5

need help for calculated total pips for order closed today (Mql5)

To add comments, please log in or register
forextime8
710
forextime8  
any helps ??
Jack Thomas
1725
Jack Thomas  
forextime8:
any helps ??
Lot's of help available on this link: https://www.mql5.com/en/job
Freelance service at MQL5.com
Freelance service at MQL5.com
  • www.mql5.com
Strategy: It starts with orders pending above and below the price of X pip spaced betweenthem, inserted on rounded price levels. When the price touches one of the twolevels the x-grid is formed at a time On each level at a distance of x pip open a buy and sell, divided into stoporders and limit orders, orders size will be calculated according...
forextime8
710
forextime8  
Jack Thomas:
Lot's of help available on this link: https://www.mql5.com/en/job

   double TotalPipClosed = 0;
   ulong Deal_Ticket;            // deal ticket 
   ulong Order_Ticket;           // ticket of the order the deal was executed on 
   datetime Deal_Execution_Time; // time of a deal execution  
   long Deal_Type ;              // type of a trade operation 
   long History_Position_ID;     // position ID 
   double History_Volume;        // operation volume 
   string History_Symbol;        // symbol of the deal 
//--- set the start and end date to request the history of deals 
   datetime Today = 1 * PeriodSeconds(PERIOD_D1);// iTime(_Symbol, PERIOD_D1, 0); // from the today open
   datetime EndOfToday = TimeCurrent();                  // till the current moment
//--- request the history of deals in the specified period 
   HistorySelect(Today, EndOfToday);
//--- total number in the list of deals 
   int Deals = HistoryDealsTotal();
//--- now process each trade 
   for(int i = 0; i < Deals; i++) 
   {
      Deal_Ticket         = HistoryDealGetTicket(i); 
      History_Volume      = HistoryDealGetDouble(Deal_Ticket, DEAL_VOLUME); 
      Deal_Execution_Time = (datetime)HistoryDealGetInteger(Deal_Ticket, DEAL_TIME); 
      Order_Ticket        = HistoryDealGetInteger(Deal_Ticket, DEAL_ORDER); 
      Deal_Type           = HistoryDealGetInteger(Deal_Ticket, DEAL_TYPE); 
      History_Symbol      = HistoryDealGetString(Deal_Ticket, DEAL_SYMBOL); 
      History_Position_ID = HistoryDealGetInteger(Deal_Ticket, DEAL_POSITION_ID);
      
      if ((Deal_Type == POSITION_TYPE_BUY) || (Deal_Type == POSITION_TYPE_SELL))
      {
         TotalPipClosed += ((HistoryDealGetInteger(Deal_Ticket, DEAL_ENTRY) == DEAL_ENTRY_OUT) - HistoryDealGetInteger(Deal_Ticket, DEAL_ENTRY) == DEAL_ENTRY_IN) / _Point;
      }
   }

still failure to get totalpips for orderclosed for current day.

where the mistake there ?

Anthony Garot
408
Anthony Garot  

Your immediate (obvious) problem is in this line:

TotalPipClosed += ((HistoryDealGetInteger(Deal_Ticket, DEAL_ENTRY) == DEAL_ENTRY_OUT) - HistoryDealGetInteger(Deal_Ticket, DEAL_ENTRY) == DEAL_ENTRY_IN) / _Point;

Break this down a bit . . .

(HistoryDealGetInteger(Deal_Ticket, DEAL_ENTRY) == DEAL_ENTRY_OUT)

. . . is a condition, that returns true/false, or in this case 1 or 0.

The same is true for:

HistoryDealGetInteger(Deal_Ticket, DEAL_ENTRY) == DEAL_ENTRY_IN

Neither of these will give you pips.

Maybe look at the function HistoryDealGetDouble() with the parameter DEAL_PROFIT.

Good luck.

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

int PriceToInteger( const double Price, const double point )
{
  return((int)(Price / point + 0.1));
}

int GetTotalPips( const datetime From = 0 )
{
  int Res = 0;
  
  for (int i = OrdersHistoryTotal() - 1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
      if (OrderCloseTime() < From)
        break;
      else if (OrderType() <= OP_SELL)
      {
        const double point = SymbolInfoDouble(OrderSymbol(), SYMBOL_POINT);
        
        Res += OrderType() ? PriceToInteger(OrderOpenPrice(), point) - PriceToInteger(OrderClosePrice(), point)
                           : PriceToInteger(OrderClosePrice(), point) - PriceToInteger(OrderOpenPrice(), point);
      }
        
  return(Res);
}

void OnStart()
{
  datetime Today = TimeCurrent();
  
  Today -= Today % PeriodSeconds(PERIOD_D1);
  
  Alert(GetTotalPips(Today));
}
forextime8
710
forextime8  
Anthony Garot:

Your immediate (obvious) problem is in this line:

Break this down a bit . . .

. . . is a condition, that returns true/false, or in this case 1 or 0.

The same is true for:

Neither of these will give you pips.

Maybe look at the function HistoryDealGetDouble() with the parameter DEAL_PROFIT.

Good luck.


you mean using HistoryDealGetDouble to get deal profit and then divide with deal volume ??

i cant find OrderClosePrice on mql5...

and what if my acc currency isnt usd, maybe jpy or gbp.

so how to convert it to actual pips gained ?

forextime8
710
forextime8  
Anthony Garot:

Your immediate (obvious) problem is in this line:

Break this down a bit . . .

. . . is a condition, that returns true/false, or in this case 1 or 0.

The same is true for:

Neither of these will give you pips.

Maybe look at the function HistoryDealGetDouble() with the parameter DEAL_PROFIT.

Good luck.


why there is no OrderClosePrice() in mql5 ?

or do there any variable same like it?

forextime8
710
forextime8  

any help ?

i stucked in this part almost 1 month alr...

forextime8
710
forextime8  

refer to somewhere on this forum,

i got this, but still doesnt give the accurate total pipsclosed.

//********************************************************************
      if (HistoryDealGetInteger(i, DEAL_ENTRY) == DEAL_ENTRY_IN)
      {
         Deal_PriceOpen = HistoryDealGetDouble(i, DEAL_PRICE);
      }
      if (HistoryDealGetInteger(i, DEAL_ENTRY) == DEAL_ENTRY_OUT)
      {
         Deal_PriceClose = HistoryDealGetDouble(i, DEAL_PRICE);
      }
      if ((Deal_Type == DEAL_TYPE_BUY))
      {
         TotalPipClosed += (Deal_PriceClose - Deal_PriceOpen) / _Point;
      }
      if ((Deal_Type == DEAL_TYPE_SELL))
      {
         TotalPipClosed += (Deal_PriceOpen - Deal_PriceClose) / _Point;
      }
//********************************************************************
fxsaber
10972
fxsaber  
forextime8:

any help ?

i stucked in this part almost 1 month alr...

Answer.

forextime8
710
forextime8  
fxsaber:

this is still mql4, isnt it ??

12
To add comments, please log in or register