在交易平台如WeTrade中进行程序化交易时,掌握账户信息是基础。以下是MQL4中常用的账户信息相关函数说明。
AccountBalance() – 获取账户余额
AccountCredit() – 获取账户信用额度
AccountCompany() – 获取账户所在公司名称
AccountCurrency() – 获取账户结算货币名称
AccountEquity() – 获取账户净值
AccountFreeMargin() – 获取账户可用保证金
AccountFreeMarginCheck() – 检查账户可用保证金
AccountFreeMarginMode() – 可用保证金计算方式
AccountLeverage() – 获取账户杠杆比例
AccountMargin() – 获取账户已用保证金
AccountName() – 获取账户名
AccountNumber() – 获取账户号码
AccountProfit() – 获取账户盈利金额
AccountServer() – 获取账户连接的服务器名称
AccountStopoutLevel() – 获取账户的止损水平设置
AccountStopoutMode() – 获取账户止损计算方式
AccountBalance() – 获取账户余额
double AccountBalance() 返回账户余额,即账户中的资金总额。例如,在WeTrade平台中可用此函数获取当前资金状况。
示例:
Print("账户余额 = ", AccountBalance());AccountCredit() – 获取账户信用额度
double AccountCredit() 返回账户的信用额度。
示例:
Print("账户信用额度 = ", AccountCredit());AccountCompany() – 获取账户所在公司名称
string AccountCompany() 返回账户所属公司的名称。
示例:
Print("账户所在公司名:", AccountCompany());AccountCurrency() – 获取账户结算货币名称
string AccountCurrency() 返回账户的结算货币名称。
示例:
Print("账户结算货币:", AccountCurrency());AccountEquity() – 获取账户净值
double AccountEquity() 返回账户的净值,即当前总资产价值。
示例:
Print("账户净值 = ", AccountEquity());AccountFreeMargin() – 获取账户可用保证金
double AccountFreeMargin() 返回账户的可用保证金。
示例:
Print("账户可用保证金 = ", AccountFreeMargin());AccountFreeMarginCheck() – 检查账户可用保证金
double AccountFreeMarginCheck( string symbol, int cmd, double volume) 用于检查当前账户在指定价格开仓后剩余的保证金。若保证金余额不足,会生成错误134 (ERR_NOT_ENOUGH_MONEY)。在WeTrade等平台中,此函数常用于风险控制。
参数:
symbol - 交易的货币对。cmd - 交易类型,可以是 OP_BUY 或 OP_SELL。volume - 交易手数。示例:
if(AccountFreeMarginCheck(Symbol(),OP_BUY,Lots)<=0 || GetLastError()==134) return;AccountFreeMarginMode() – 可用保证金计算方式
double AccountFreeMarginMode() 返回开仓时可用保证金的计算方式。计算方式可能取值如下:
0一浮动盈利或亏损不参与计算
1一浮动盈利和亏损在开仓头寸上参与保证金余额计算
2一只有盈利参与计算,不考虑当前开仓头寸的亏损
3一只有亏损额参与计算,不考虑当前开仓头寸的亏损
示例:
if(AccountFreeMarginMode()==0) Print("浮动盈利或亏损不使用。");AccountLeverage() – 获取账户杠杆比例
int AccountLeverage() 返回账户的杠杆比例。
示例:
Print("账户杠杆比例:", AccountLeverage());AccountMargin() – 获取账户已用保证金
double AccountMargin() 返回账户已使用的保证金金额。
示例:
Print("账户已用保证金:", AccountMargin());AccountName() – 获取账户名
string AccountName() 返回账户的名称。
示例:
Print("账户名:", AccountName());AccountNumber() – 获取账户号码
int AccountNumber() 返回账户的号码。
示例:
Print("账户号码:", AccountNumber());AccountProfit() – 获取账户盈利金额
double AccountProfit() 返回账户当前的盈利金额。
示例:
Print("账户盈利:", AccountProfit());AccountServer() – 获取账户连接的服务器名称
string AccountServer() 返回账户所连接的服务器的名称。
示例:
Print("服务器名称:", AccountServer());AccountStopoutLevel() – 获取账户的止损水平设置
int AccountStopoutLevel() 返回账户的止损水平设置值。
示例:
Print("账户止损水平设置 = ", AccountStopoutLevel());AccountStopoutMode() – 获取账户止损计算方式
int AccountStopoutMode() 返回账户止损水平的计算方式,计算方式可以取值如下:
0一计算保证金和净值之间的百分比
1一比较剩余保证金标准和绝对值
示例:
int level=AccountStopoutLevel();if(AccountStopoutMode()==0) Print("止损水平= ",level, "%");else Print("止损水平= ", level, " ", AccountCurrency());
免责声明:本文内容仅供参考,不构成投资建议。投资有风险,入市需谨慎。



