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.
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.
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.
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/126192https://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
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.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Is there a way to access the initial deposit in my EA?