Download MetaTrader 5
To add comments, please log in or register
Freelance service: the safe way to order a trading robot. Try it!
Sherif Hasan
7224
Sherif Hasan 2015.08.03 05:11 
int Total = OrdersTotal();
double BalanceUsed = AccountBalance();
double Balance;

for (int i = 0; i < Total; i++)
    {
    OrderSelect(i,SELECT_BY_POS, MODE_TRADES);
    if(OrderType() == OP_BUY || OrderType() == OP_SELL)
        {
        Balance = Balance - OrderProfit();
        }
    }

for (int p = 0; p < HistoryTotal(); p ++)
    {
    OrderSelect(i,SELECT_BY_POS, MODE_HISTORY);
    if(OrderType() == OP_BUY || OrderType() == OP_SELL)
        {
        Balance = Balance - OrderProfit();
        }
    }

Comment("Intial Deposit was: "+Balance);

What wrong with this code?

I don't get the deposit amount. i want to find intial deposit amount to calculate the drawdown to avoid risk in trades to reduce drawdown.

Help on this issue.

whroeder1
13656
whroeder1 2015.08.03 13:38  
  1. open orders do not change AccountBalance
  2. There is no functon HistoryTotal()
  3. profit = OrderProfit() + OrderCommission() + OrderSwap()
  4. Check your return codes (OrderSelect) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Sherif Hasan
7224
Sherif Hasan 2015.08.03 16:10  

Got the Code here: https://forum.mql4.com/62016

for(int i = OrdersHistoryTotal() -1; i >= 0; i--)
   {
   if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
      {
      if (OrderType() == 6)
         {
         Comment("The Deposit Was ", OrderProfit(), " ", AccountCurrency());
         }
      }
   }


But it works only when we have opened All History on History Tab.

is there any other solutions to get the intial deposit?

/
To add comments, please log in or register