跳至内容

Account Properties

账户属性

要获取当前账户的信息,可以使用以下几种函数:AccountInfoInteger()AccountInfoDouble()AccountInfoString()。这些函数的参数值可以接受来自相应ENUM_ACCOUNT_INFO枚举的值。

对于函数AccountInfoInteger()

ENUM_ACCOUNT_INFO_INTEGER

标识符描述类型
ACCOUNT_LOGIN账户号码long
ACCOUNT_TRADE_MODE账户交易模式ENUM_ACCOUNT_TRADE_MODE
ACCOUNT_LEVERAGE账户杠杆率long
ACCOUNT_LIMIT_ORDERS允许的最大开仓数量和活跃待处理订单总数,0表示无限int
ACCOUNT_MARGIN_SO_MODE设置最小允许保证金的模式ENUM_ACCOUNT_STOPOUT_MODE
ACCOUNT_TRADE_ALLOWED当前账户的允许交易类型bool
ACCOUNT_TRADE_EXPERT专家顾问的允许交易类型bool

对于函数AccountInfoDouble()

ENUM_ACCOUNT_INFO_DOUBLE

标识符描述类型
ACCOUNT_BALANCE账户在存款货币中的余额double
ACCOUNT_CREDIT账户在存款货币中的信用额double
ACCOUNT_PROFIT账户当前利润,以存款货币计double
ACCOUNT_EQUITY账户在存款货币中的资产价值double
ACCOUNT_MARGIN账户使用的保证金,以存款货币计double
ACCOUNT_MARGIN_FREE账户的免费保证金double
ACCOUNT_MARGIN_LEVEL账户保证金水平,以百分比计double
ACCOUNT_MARGIN_SO_call保证金催缴水平。根据设置的ACCOUNT_MARGIN_SO_MODE,以百分比或存款货币表示double
ACCOUNT_MARGIN_SO_SO保证金停止出局水平。根据设置的ACCOUNT_MARGIN_SO_MODE,以百分比或存款货币表示double
ACCOUNT_MARGIN_INITIAL不支持double
ACCOUNT_MARGIN_MAINTENANCE不支持double
ACCOUNT_ASSETS不支持double
ACCOUNT_LIABILITIES不支持double
ACCOUNT_COMMISSION_BLOCKED不支持double

对于函数AccountInfoString()

ENUM_ACCOUNT_INFO_STRING

标识符描述类型
ACCOUNT_NAME客户端名称string
ACCOUNT_SERVER交易服务器名称string
ACCOUNT_CURRENCY账户货币string
ACCOUNT_COMPANY服务该账户的公司名称string

可以在交易服务器上开设多种类型的账户。可以使用ENUM_ACCOUNT_TRADE_MODE枚举来查看运行MQL4程序的账户类型。

ENUM_ACCOUNT_TRADE_MODE

标识符描述
ACCOUNT_TRADE_MODE_DEMO演示账户
ACCOUNT_TRADE_MODE_CONTEST竞赛账户
ACCOUNT_TRADE_MODE_REAL真实账户

如果资产不足以维持开仓订单,则会发生停止出局情况,即被迫平仓。停止出局发生的最低保证金水平可以以百分比或货币单位设置。要查看账户设置的模式,请使用ENUM_ACCOUNT_STOPOUT_MODE枚举。

ENUM_ACCOUNT_STOPOUT_MODE

标识符描述
ACCOUNT_STOPOUT_MODE_PERCENT账户停止出局模式,以百分比表示
ACCOUNT_STOPOUT_MODE_MONEY账户停止出局模式,以货币单位表示

以下是一个输出简要账户信息的脚本示例。

//+------------------------------------------------------------------+
//| 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);
  }
最后更新于