How to get AccountNumber and AccountName

 

Hi folks.

I have a little problem.

if ( IsConnected() ) {  // terminal is online

   AccountNumber();     // returns correct account number

   AccountName();       // returns correct account name

} else {                // terminal is OFFLINE

   AccountNumber();     // returns "0" zero

   AccountName();       // returns empty value

}


The correct number of the account is shown at the top of the terminal window but AccountNumber() returns a zero.

How to get correct Account data when terminal is offline.


Sorry for my english.

 

The server of your broker provides this information. If you are not connected these (and other) functions do not return valid values!

It could even be that for example after a restart of the terminal the Oninit() is executed while the terminal is still in the progress to login and you might get wrong values in this case - imagine a thread race and you haven't won it.

 
gooly:

The server of your broker provides this information. If you are not connected these (and other) functions do not return valid values!

It could even be that for example after a restart of the terminal the Oninit() is executed while the terminal is still in the progress to login and you might get wrong values in this case - imagine a thread race and you haven't won it.

That is 100% correct but any offline terminal can read data such as AccountNumber and AccountName. See Navigator->Accounts.
 
Solarix:
That is 100% correct but any offline terminal can read data such as AccountNumber and AccountName. See Navigator->Accounts.
Interesting! While I do see the point, you are otoh misleading here. What you see in Navigator->Accounts are a list of accounts that you can have. E.g. You can have multiple Brokers and accounts. Demo account, Real account etc. These informations are strings (text) stored either in the registry or config files inside Window or MetaTrader, so you can quickly click on them and connect to one of them. The functions you are referring to (above in your code examples) are related to the *currently connected account* and have nothing to do with the strings listed in the Navigator (see it as an address book).
 
Until you connect, log in, and receive the server response, there is no account. Don't call them until you get the first tick.
Reason: