Account balance in %
Hi, simple question, is it posible to write account balance in percentage?
why for egz. this :
if (AccountBalance()<90%) lot=0.02;
cannot work instead of this:
if (AccountBalance()<300) lot=0.02;
This is not a programming issue so much as a maths question.
It seems as if you want to look at how depleted the account has become. In this case you need to remember the initial value.
So initially you will want to set ...
double initialBalance = AccountBalance();
Then at some later point you can calculate the required value ...
double percentAccountBalance= 100.0* AccountBalance()/initialBalance;
Then and only then can you write your test ...
if( percentAccountBalance < 90.0 ) lot=0.02;
but don’t use the percentage sign.
So initially you will want to set ..
double initialBalance = AccountBalance();
That won't work unless it's a static or global.
Instead just compute it
double initialBalance = AccountBalance(); int nHist = 0; for(int iPos=OrdersHistoryTotal()-1; iPos >= 0 ; iPos--) if ( OrderSelect(iPos, SELECT_BY_POS, MODE_HISTORY) // Only orders w/ && OrderMagicNumber() == Magic.Number // my magic number && OrderSymbol() == chart.symbol // and my pair. && OrderType() <= OP_SELL// Avoid cr/bal forum.mql4.com/32363#325360 ){ double profit = OrderProfit() + OrderSwap() + OrderCommission(); initialBalance -= profit; nHist++; if (nHist == max.Lookback) break; }
Hi, simple question, is it posible to write account balance in percentage?
why for egz. this :
if (AccountBalance()<90%) lot=0.02;
cannot work instead of this:
if (AccountBalance()<300) lot=0.02;