Skip to content

Account Properties

Account Properties

To obtain information about the current account there are several functions: AccountInfoInteger(), AccountInfoDouble() and AccountInfoString(). The function parameter values can accept values from the corresponding ENUM_ACCOUNT_INFO enumerations.

For the function AccountInfoInteger()

ENUM_ACCOUNT_INFO_INTEGER

IdentifierDescriptionType
ACCOUNT_LOGINAccount numberlong
ACCOUNT_TRADE_MODEAccount trade modeENUM_ACCOUNT_TRADE_MODE
ACCOUNT_LEVERAGEAccount leveragelong
ACCOUNT_LIMIT_ORDERSMaximum allowed number of active pending ordersint
ACCOUNT_MARGIN_SO_MODEMode for setting the minimal allowed marginENUM_ACCOUNT_STOPOUT_MODE
ACCOUNT_TRADE_ALLOWEDAllowed trade for the current accountbool
ACCOUNT_TRADE_EXPERTAllowed trade for an Expert Advisorbool
ACCOUNT_MARGIN_MODEMargin calculation modeENUM_ACCOUNT_MARGIN_MODE
ACCOUNT_CURRENCY_DIGITSThe number of decimal places in the account currency, which are required for an accurate display of trading resultsint
ACCOUNT_FIFO_CLOSEAn indication showing that positions can only be closed by FIFO rule. If the property value is set to true, then each symbol positions will be closed in the same order, in which they are opened, starting with the oldest one. In case of an attempt to close positions in a different order, the trader will receive an appropriate error.

For accounts with the non-hedging position accounting mode (ACCOUNT_MARGIN_MODE!=ACCOUNT_MARGIN_MODE_RETAIL_HEDGING), the property value is always false.
bool
ACCOUNT_HEDGE_ALLOWEDAllowed opposite positions on a single symbolbool

For the function AccountInfoDouble()

ENUM_ACCOUNT_INFO_DOUBLE

IdentifierDescriptionType
ACCOUNT_BALANCEAccount balance in the deposit currencydouble
ACCOUNT_CREDITAccount credit in the deposit currencydouble
ACCOUNT_PROFITCurrent profit of an account in the deposit currencydouble
ACCOUNT_EQUITYAccount equity in the deposit currencydouble
ACCOUNT_MARGINAccount margin used in the deposit currencydouble
ACCOUNT_MARGIN_FREEFree margin of an account in the deposit currencydouble
ACCOUNT_MARGIN_LEVELAccount margin level in percentsdouble
ACCOUNT_MARGIN_SO_CALLMargin call level. Depending on the set ACCOUNT_MARGIN_SO_MODE is expressed in percents or in the deposit currencydouble
ACCOUNT_MARGIN_SO_SOMargin stop out level. Depending on the set ACCOUNT_MARGIN_SO_MODE is expressed in percents or in the deposit currencydouble
ACCOUNT_MARGIN_INITIALInitial margin. The amount reserved on an account to cover the margin of all pending ordersdouble
ACCOUNT_MARGIN_MAINTENANCEMaintenance margin. The minimum equity reserved on an account to cover the minimum amount of all open positionsdouble
ACCOUNT_ASSETSThe current assets of an accountdouble
ACCOUNT_LIABILITIESThe current liabilities on an accountdouble
ACCOUNT_COMMISSION_BLOCKEDThe current blocked commission amount on an accountdouble

For function AccountInfoString()

ENUM_ACCOUNT_INFO_STRING

IdentifierDescriptionType
ACCOUNT_NAMEClient namestring
ACCOUNT_SERVERTrade server namestring
ACCOUNT_CURRENCYAccount currencystring
ACCOUNT_COMPANYName of a company that serves the accountstring

There are several types of accounts that can be opened on a trade server. The type of account on which an MQL5 program is running can be found out using the ENUM_ACCOUNT_TRADE_MODE enumeration.

ENUM_ACCOUNT_TRADE_MODE

IdentifierDescription
ACCOUNT_TRADE_MODE_DEMODemo account
ACCOUNT_TRADE_MODE_CONTESTContest account
ACCOUNT_TRADE_MODE_REALReal account

In case equity is not enough for maintaining open positions, the Stop Out situation, i.e. forced closing occurs. The minimum margin level at which Stop Out occurs can be set in percentage or in monetary terms. To find out the mode set for the account use the ENUM_ACCOUNT_STOPOUT_MODE enumeration.

ENUM_ACCOUNT_STOPOUT_MODE

IdentifierDescription
ACCOUNT_STOPOUT_MODE_PERCENTAccount stop out mode in percents
ACCOUNT_STOPOUT_MODE_MONEYAccount stop out mode in money

ENUM_ACCOUNT_MARGIN_MODE

IdentifierDescription
ACCOUNT_MARGIN_MODE_RETAIL_NETTINGUsed for the OTC markets to interpret positions in the “netting” mode (only one position can exist for one symbol). The margin is calculated based on the symbol type (SYMBOL_TRADE_CALC_MODE).
ACCOUNT_MARGIN_MODE_EXCHANGEUsed for the exchange markets. Margin is calculated based on the discounts specified in symbol settings. Discounts are set by the broker, but not less than the values set by the exchange.
ACCOUNT_MARGIN_MODE_RETAIL_HEDGINGUsed for the exchange markets where individual positions are possible (hedging, multiple positions can exist for one symbol). The margin is calculated based on the symbol type (SYMBOL_TRADE_CALC_MODE) taking into account the hedged margin (SYMBOL_MARGIN_HEDGED).

An example of the script that outputs a brief account information.

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- Name of the company
   string company=AccountInfoString(ACCOUNT_COMPANY);
//--- Name of the client
   string name=AccountInfoString(ACCOUNT_NAME);
//--- Account number
   long login=AccountInfoInteger(ACCOUNT_LOGIN);
//--- Name of the server
   string server=AccountInfoString(ACCOUNT_SERVER);
//--- Account currency
   string currency=AccountInfoString(ACCOUNT_CURRENCY);
//--- Demo, contest or real account
   ENUM_ACCOUNT_TRADE_MODE account_type=(ENUM_ACCOUNT_TRADE_MODE)AccountInfoInteger(ACCOUNT_TRADE_MODE);
//--- Now transform the value of  the enumeration into an understandable form
   string trade_mode;
   switch(account_type)
     {
      case  ACCOUNT_TRADE_MODE_DEMO:
         trade_mode="demo";
         break;
      case  ACCOUNT_TRADE_MODE_CONTEST:
         trade_mode="contest";
         break;
      default:
         trade_mode="real";
         break;
     }
//--- Stop Out is set in percentage or money
   ENUM_ACCOUNT_STOPOUT_MODE stop_out_mode=(ENUM_ACCOUNT_STOPOUT_MODE)AccountInfoInteger(ACCOUNT_MARGIN_SO_MODE);
//--- Get the value of the levels when Margin Call and Stop Out occur
   double margin_call=AccountInfoDouble(ACCOUNT_MARGIN_SO_CALL);
   double stop_out=AccountInfoDouble(ACCOUNT_MARGIN_SO_SO);
//--- Show brief account information
   PrintFormat("The account of the client '%s' #%d %s opened in '%s' on the server '%s'",
               name,login,trade_mode,company,server);
   PrintFormat("Account currency - %s, MarginCall and StopOut levels are set in %s",
               currency,(stop_out_mode==ACCOUNT_STOPOUT_MODE_PERCENT)?"percentage":" money");
   PrintFormat("MarginCall=%G, StopOut=%G",margin_call,stop_out);
  }
Last updated on