Need Help with SummaryReport.mq4

 
I need Help

I have written a EA, that sets the lots as a function of the Initial Deposit:
Lots=CalculateInitialDeposit()/K; // K has been set to 5000

The problem I have is that at some point AFTER the initial Desposit, I have ADDED funds to my account and would
like the lots to be incremented. But the CalculateInitialDeposit() function does not consider the ADDITION or SUBSTRACTION of funds from the account.

I need the code to add to the CalculateInitialDeposit() function so it takes care of this situation.

(Alternatively parhaps a OrderXXXX function, or a new OrderType implemented)

Help greatly appreciated
 
Additions and subtractions are processed with operation OP_BALANCE (integer value 6). This operations are considered
if(type==OP_BALANCE || type==OP_CREDIT)
initial_deposit-=OrderProfit();

negative profit of this operation means withdrawal (subtraction)
positive profit means deposit (addition)
double CalculateInitialDeposit()
  {
   double initial_deposit=AccountBalance();
//----
   for(int i=HistoryTotal()-1; i>=0; i--)
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
      int type=OrderType();
      //---- initial balance not considered
      if(i==0 && type==OP_BALANCE) break;
      if(type==OP_BUY || type==OP_SELL)
        {
         //---- calculate profit
         double profit=OrderProfit()+OrderCommission()+OrderSwap();
         //---- and decrease balance
         initial_deposit-=profit;
        }
      if(type==OP_BALANCE || type==OP_CREDIT)
         initial_deposit-=OrderProfit();
     }
//----
   return(initial_deposit);
  }




 
Slawa

I added the above function to my EA, but it only considers the initial balance. Please see account 900039 investor PW Paul123

the above function only considers the 6900 initial deposit and nothing else namely the 7000 added by Ticket 3398
I would need the equivalent to the deposit/withdrawal number from the Report
 
I would need the equivalent to the deposit/withdrawal number from the Report

Very simple question.
#define OP_BALANCE 6
...

   double deposit=0.0,withdrawal=0.0;
   int    total=HistoryTotal();
//----
   for(int i=0; i<total; i++)
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
      if(OrderType()!=OP_BALANCE) continue;
      double profit=OrderProfit();
      if(profit>0) deposit+=profit;
      else withdrawal+=profit;
     }

 
Thanks Slawa...
I solved it as follows

double CalculateInitialDeposit()
{
double initial_deposit=AccountBalance();
//----
for(int i=HistoryTotal()-1; i>=0; i--)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
int type=OrderType();
//---- initial balance not considered
if(i==0 && type==OP_BALANCE) break;
if(type==OP_BUY || type==OP_SELL || type==OP_BALANCE)
{
//---- calculate profit
double profit=OrderProfit()+OrderCommission()+OrderSwap();
//---- and decrease balance
initial_deposit-=profit;
}
if(type==OP_BALANCE || type==OP_CREDIT)
initial_deposit-=OrderProfit();
}
//----
Print( initial_deposit);
return(initial_deposit);