Account Balance is 0 in a demo account?

 

Hi, how do I get the account balance in a demo account?

The following gives me 0.....maybe there's another way to call it?


AccountInfoDouble(ACCOUNT_BALANCE)

AccountBalance();

 
double balance = AccountInfoDouble(ACCOUNT_BALANCE);

See Here.

Documentation on MQL5: Account Information / AccountInfoDouble
Documentation on MQL5: Account Information / AccountInfoDouble
  • www.mql5.com
Account Information / AccountInfoDouble - Reference on algorithmic/automated trading language for MetaTrader 5
 
Marco vd Heijden:

See Here.

I did that too; it's still 0; both are showing 0, but it's not 0 in demo account.


Print(AccountInfoDouble(ACCOUNT_BALANCE));
Print(AccountBalance());
 
I had some issue too.
Choose another demo account with  broker then it works.
Don't use Metaquotes demo account, not reliable (at least for me).

 
Kok Hoong Cheang: I have no idea why the following code reveals account balance is 0.

Don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:

  1. Terminal starts.
  2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
  3. OnInit is called.
  4. For indicators OnCalculate is called with any existing history.
  5. Human may have to enter password, connection to server begins.
  6. New history is received, OnCalculate called again.
  7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
 

Thanks, putting the code in OnCalculate/OnTick works; I was putting it OnChartEvent