Account Properties
账户属性
要获取当前账户的信息,可以使用以下几种函数:AccountInfoInteger()、AccountInfoDouble()和AccountInfoString()。这些函数的参数值可以接受来自相应ENUM_ACCOUNT_INFO枚举的值。
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 |
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 |
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);
}最后更新于