AccountInfoDouble(ACCOUNT_BALANCE) returns 0 in Demo account with 10000$ balance

 

Hello!

I have a demo account and in my client Trade tab I can see that I have 10000 Balance, Equity, and Free margin but when I call AccountInfoDouble(ACCOUNT_BALANCE) in my Expert Advisor I get returned 0, this also happens with Equity and Free Margin.

Might this be because this is a demo account or is it something else?

 
Azkron:

Hello!

I have a demo account and in my client Trade tab I can see that I have 10000 Balance, Equity, and Free margin but when I call AccountInfoDouble(ACCOUNT_BALANCE) in my Expert Advisor I get returned 0, this also happens with Equity and Free Margin.

Might this be because this is a demo account or is it something else?

I don't think. How did you check the returned value ? 

 
Icham Aidibe:

I don't think. How did you check the returned value ? 


 
printf("ACCOUNT_BALANCE =  %d", AccountInfoDouble(ACCOUNT_BALANCE)); 
printf("ACCOUNT_CREDIT =  %d", AccountInfoDouble(ACCOUNT_CREDIT)); 
printf("ACCOUNT_PROFIT =  %d", AccountInfoDouble(ACCOUNT_PROFIT));  
printf("ACCOUNT_EQUITY =  %d", AccountInfoDouble(ACCOUNT_EQUITY)); 
printf("ACCOUNT_MARGIN =  %d", AccountInfoDouble(ACCOUNT_MARGIN));

They all print 0

 
Azkron:

Use : %g

 
  1. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Where do you have that code? Probably in OnInit.
    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 and prices are valid.
  3. d, i, u, o, x, X are all the integer group. Try %f or %g
              Common Functions / PrintFormat - Reference on algorithmic/automated trading language for MetaTrader 5
 
whroeder1:
  1. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Where do you have that code? Probably in OnInit.
  3. d, i, u, o, x, X are all the integer group. Try %f or %g
              Common Functions / PrintFormat - Reference on algorithmic/automated trading language for MetaTrader 5

Thanks, now I print it the first time OnTick() triggers and the values look correct.