Initial Deposit

 

Is there a way to access the initial deposit in my EA?

 
Ugh I'll be interested to know as well.
 

A suggestion . . not sure if will work, but it might.

Check your order history and check the comments for "Deposit"

 

Roflmao!!!!!

I guess I should have done my homework myself.

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
   for(int i = OrdersHistoryTotal()-1; i >= 0; i--){
      OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
      Print(OrderTicket(), OrderComment(), OrderMagicNumber());
   }
   

   return(0);
  }
//+----
Quick script for testing all history, and indeed the first one is the Deposit.
 

Some strategies require the comment field for something else, more general solution is:

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
   double deposit=AccountBalance();
   for(int i = OrdersHistoryTotal()-1; i >= 0; i--){
      OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
      deposit+= (OrderProfit()+OrderSwap()+OrderCommission());
   }
   
   Print(deposit);

   return(0);
  }
//+----

At least this should work.

 
zzuegg:

Some strategies require the comment field for something else, more general solution is:

At least this should work.

It may work as long as the Account History is set to show All History . . if you check the comment field as well and it is set to "Deposit" then you have confirmation.
 

Some brokers do modify the comment after an order has closed, some to even change the comment set by you or your ea.

One of my systems needs the comment field from open trades to be able to recovery from a failure.

Theoretically there should also be another OrderType() which handles transfers of funds. I can check that when i am at home.

 
zzuegg:

Some brokers do modify the comment after an order has closed, some to even change the comment set by you or your ea.

One of my systems needs the comment field from open trades to be able to recovery from a failure.

Theoretically there should also be another OrderType() which handles transfers of funds. I can check that when i am at home.

OrderType = 6 . . Balance, from the looks of it.
 
    static datetime lastClose;  datetime lastClosePrev = lastClose;
    for(int pos=0; pos < OrdersHistoryTotal(); pos++) if (
        OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)   // Only orders w/
    &&  OrderCloseTime()    > lastClosePrev             // not yet processed,
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol()                 // and my pair.
    &&  OrderType()         <= OP_SELL){    // Avoid cr/bal https://www.mql5.com/en/forum/126192
https://www.mql5.com/en/forum/126192
 

here https://forum.mql4.com/30708 in the forum it mentions that there are undocumented order types of 6 and 7 (balance and credits). Balance order types refer to withdrawals and deposits. I use the following simple function in my EAs to return the current deposited amount in the account minus withdrawals (ie withdrawals are subtracted automatically through the fact they are negative numbers)

Apparently credits are brokers added funds, you could add this to the function with if(OrderType() == 6 || OrderType() == 7) instead.

double getDeposit(){

int total, cnt;
double deposits;

deposits = 0;
total=OrdersHistoryTotal();

for(cnt=0;cnt<total;cnt++){

OrderSelect(cnt, SELECT_BY_POS, MODE_HISTORY);

if(OrderType() == 6){

deposits+ = OrderProfit();


}

}

return(deposits);

}


Cheers

Paul

 
zzuegg:

Some brokers do modify the comment after an order has closed, some to even change the comment set by you or your ea.

One of my systems needs the comment field from open trades to be able to recovery from a failure.

Theoretically there should also be another OrderType() which handles transfers of funds. I can check that when i am at home.


I use the comment field as part of my failure recovery too I am beginning to wonder if maybe thats not such a good idea as I keep hearing how brokers change the comment i might go back to my original idea which was to use the magic number field.
Reason: