Incorrected account number returned

 
For an MT5 demo account on [Redacted] I try to use mql5 to retrieve the account number using "AccountInfoInteger(ACCOUNT_LOGIN)" and as can be seen form the attached screenshot instead of getting my account number 3000051923, I am fed back with a negative number that does not look like any account number other then the fact that it contains 10 numbers, namely -1294915373.

Has anybody experience this before or knows of alternatives to retrieve an account number with MQL5? 

Googling this did not yield any result and [Redacted] assumes it is an MQL5 issue, hence the post.  

Files:
image_144e.png  38 kb
 
Use ulong to declare the variable to the acct. number - it's n overflow.
 
nwesterhuijs:
For an MT5 demo account on [Redacted] I try to use mql5 to retrieve the account number using "AccountInfoInteger(ACCOUNT_LOGIN)" and as can be seen form the attached screenshot instead of getting my account number 3000051923, I am fed back with a negative number that does not look like any account number other then the fact that it contains 10 numbers, namely -1294915373.

Has anybody experience this before or knows of alternatives to retrieve an account number with MQL5? 

Googling this did not yield any result and [Redacted] assumes it is an MQL5 issue, hence the post.  

The AccountInfoInteger(ACCOUNT_LOGIN) function is used to retrieve the login (account number) of the currently authorized user. The return value should be a positive integer representing the account number. However, if you're getting a negative number like -1294915373, it indicates that something unexpected is happening.

Here are a few steps to help you troubleshoot this issue:

  1. Check Authorization: Make sure that you are properly authorized and logged into your MT5 demo account. If you're not logged in or the connection is unstable, it might affect the account number retrieval.

  2. Syntax and Usage: Ensure that you are using the correct syntax for the AccountInfoInteger function. The correct syntax is:
int accountNumber = AccountInfoInteger(ACCOUNT_LOGIN);
  1. Make sure that you're storing the result in an integer variable.

  2. Testing Outside of Expert Advisor: Try running the account number retrieval code outside of an Expert Advisor (EA) in a standalone script. This will help you isolate the issue and determine if it's related to the specific EA's context.

  3. Check Platform and Broker: Verify that you are using MetaTrader 5 and that you are connected to the correct broker's demo server. Sometimes, the broker's server setup might cause unexpected behavior.

  4. MetaEditor Restart: Sometimes, the MetaEditor might not refresh properly. Close and reopen the MetaEditor to ensure that you're working with the latest version of your code.

  5. Error Handling: Add error handling to your code to catch potential issues and log them for further analysis. For example:

int accountNumber = AccountInfoInteger(ACCOUNT_LOGIN);
if (accountNumber < 0)
{
    Print("Error retrieving account number: ", GetLastError());
}

Using ulong (unsigned long) to declare the variable for the account number should not fundamentally change the behavior of the AccountInfoInteger(ACCOUNT_LOGIN) function. The account number is typically represented as a positive integer, and using ulong is a way to explicitly indicate that the variable should only hold positive values.

However, I recommend caution when using ulong for this purpose. While using ulong can prevent negative values from being stored in the variable, the function itself ( AccountInfoInteger ) should already return a positive value for the account number. If you find that you're getting negative values using int to store the account number, it's likely indicative of an issue that needs to be addressed rather than simply switching to ulong .

Before changing the variable type to ulong , I strongly recommend investigating and addressing the underlying issue causing the incorrect behavior. Properly handling the account number using the correct data type ( int ) is the standard approach and should work as intended.

If you do decide to use ulong , here's how you would declare and use it:

ulong accountNumber = AccountInfoInteger(ACCOUNT_LOGIN);
Print("Account Number: ", accountNumber);
You are free to try any of these that are relevant. Hope you manage. :-)
 

Thank you both for replying and providing a solution.  

ulong did initially work and I did some further investigation as suggested. Although I had initially tried a long definition, it did not resolved it in my code. I initially received a warning with some of the provided code and by changing the int into a long definition it did resolve it as well. 

long accountNumber = AccountInfoInteger(ACCOUNT_LOGIN);

if (accountNumber < 0)
{
    Print("Error retrieving account number: ", GetLastError());
}   

Print("Account Number: ", accountNumber);
Reason: