Current and previous total profits/balance

 

Hello,



I had yet ask this question, but the answer didn't work.



I'm making Money Managment for my EA and I need to know/calculate total profits for the current day only and total profits for all previous days (from the begining of the month)



I need also know/calculate total balance day per day for the current month (current day and previous days from the begining of the month)



Have you got any idea or piece of code please ?



Thank you,

Have a nice day.

 

Sorry, but there isn't any code which help me in this article...



is it so hard to define previous day balance and current day profit ?



I looked for in many EA with Money Management, but didn't see anything like I need...



Please, if someone have a piece of code to calculate this...



Thank you...

 

1. Get and store AccountBalance

2. Make HistoryTotal loop

3. Check close time of every trade in the history

4. If close time is more or equal today 0:00:00 calculate its profit

5. Subtract calculated profit from stored balance

You can find all this code (except close time checking) by my reference above

 

Hello Stringo,



Thank you for your answer...

About the link you provide, there is an error in the code :

OP_BALANCE and OP_CREDIT don't work in the CalculateInitialDeposit function.

I think the code is too old and don't work with newer MetaTrader versions.

If you have the correct code for this function, it could be interesting.


Thank you.

 

there are macro definitions somewhere in sources

#define OP_BALANCE 6

#define OP_CREDIT 7

 
 // Define variables
      datetime today = TimeLocal();
      double todayBalance = AccountBalance();
      int todayOrders = OrdersTotal();
      
      // Get today's profit
      double todayProfit = 0;
      for(int i = 0; i < todayOrders; i++)
       {
          if(OrderSelect(i, SELECT_BY_POS))
           {
              if(OrderSymbol() == _Symbol )
               {
                  double orderProfit = OrderProfit();
                  todayProfit += orderProfit;
              }
          }
      }
      
      // Estimate previous day's closing balance
      datetime prevDay = today - PeriodSeconds(PERIOD_D1);
      double balance_start = todayBalance - todayProfit;
      
    Comment("Previous day's closing balance: ", balance_start);
Reason: