Help, profit history

 
Hi, is there a function that returns the historic profit of the day ?
 
signal.it: Hi, is there a function that returns the historic profit of the day ?

One function? No!

Several functions that are related and can be used to access that information? Yes!

Documentation on MQL5: Trade Functions
Documentation on MQL5: Trade Functions
  • www.mql5.com
Trade Functions - Reference on algorithmic/automated trading language for MetaTrader 5
 
signal.it:
Hi, is there a function that returns the historic profit of the day ?

You may select orders from history in a loop, check its open time or close time, sum up its profit/loss.

 

I think it can be done using custom date function, but you have to do it manually on the history tab.

 
signal.it:
Hi, is there a function that returns the historic profit of the day ?
// MQL4&5-code

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

#define DAY (24 * 3600)

double GetPofitDay( const datetime timeDay )
{
  const datetime BeginTime  = timeDay - (timeDay % DAY);
  const datetime EndTime = BeginTime + DAY;
  
  double Res = 0;
  
  for (int i = OrdersHistoryTotal() - 1; (i >= 0) && OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && (OrderCloseTime() >= BeginTime); i--)
    if ((OrderCloseTime() < EndTime) && (OrderType() <= OP_SELL))
      Res += OrderProfit() + OrderCommission() + OrderSwap();
  
  return(Res);
}

void OnStart()
{
  Alert("Today Profit = " + (string)GetPofitDay(TimeCurrent()));
  Alert("Yesterday Profit = " + (string)GetPofitDay(TimeCurrent() - DAY));
}
Reason: