EA编程教程详解账户函数
EA编程教程中,账户函数是开发者必须掌握的基础工具。通过这些函数,可以轻松获取交易账户的各种关键数据,为策略编写提供重要参考。以下是常用账户函数的功能说明与使用示例。
AccountBalance()
AccountCredit()
AccountCompany()
AccountCurrency()
AccountEquity()
AccountFreeMargin()
AccountFreeMarginCheck()
AccountFreeMarginMode()
AccountLeverage()
AccountMargin()
AccountName()
AccountNumber()
AccountProfit()
AccountServer()
AccountStopoutLevel()
AccountStopoutMode()
double AccountBalance()
返回账户余额,即账户中当前可用的资金总额。
示例:
Print("账户余额= ",AccountBalance());
double AccountCredit()
返回账户的信用点数,便于了解账户的信用状况。
示例:
Print("账户点数 ", AccountCredit());
string AccountCompany()
返回账户所属的公司名称。
示例:
Print("账户公司名", AccountCompany());
string AccountCurrency()
返回账户使用的货币名称。
示例:
Print("账户货币对", AccountCurrency());
double AccountEquity()
返回当前账户的资产净值,该数值会根据交易服务器的设置而变化。
示例:
Print("账户净值 = ",AccountEquity());
double AccountFreeMargin()
返回当前账户的可用保证金金额。
示例:
Print("账户免费保证金 = ",AccountFreeMargin());
double AccountFreeMarginCheck(string symbol, int cmd, double volume)
在指定开仓价格下,返回当前账户的可用保证金。如果可用保证金不足,系统会生成错误134(ERR_NOT_ENOUGH_MONEY)。
参数说明:
symbol —— 交易品种代码。
cmd —— 交易操作类型,可以是OP_BUY或OP_SELL。
volume —— 交易手数。
示例:
if(AccountFreeMarginCheck(Symbol(),OP_BUY,Lots)<=0 || GetLastError()==134) return;
double AccountFreeMarginMode()
返回当前账户计算可用保证金的模式,模式决定浮动盈亏的使用方式:
0 —— 不使用浮动盈亏计算可用保证金;
1 —— 同时使用浮动盈利和亏损来计算可用保证金;
2 —— 仅使用浮动盈利计算,不考虑浮动亏损;
3 —— 仅使用浮动亏损计算,不考虑浮动盈利。
示例:
if(AccountFreeMarginMode()==0)
Print("浮点盈利/亏损不使用。");
int AccountLeverage()
返回当前账户的杠杆比例。
示例:
Print("账户#",AccountNumber(), " 杠杆比率", AccountLeverage());
double AccountMargin()
返回当前账户占用的保证金金额。
示例:
Print("账户保证金 ", CWG MarketsAccountMargin());
string AccountName()
返回当前账户的名称。
示例:
Print("账户名称", AccountName());
int AccountNumber()
返回当前账户的编号。
示例:
Print("账户数字", AccountNumber());
double AccountProfit()
返回当前账户的浮动盈亏。
示例:
Print("账户利润", AccountProfit());
string AccountServer()
返回当前连接服务器的名称。
示例:
Print("服务器名称", AccountServer());
int AccountStopoutLevel()
返回账户的止损水平值。
示例:
Print("停止水平 = ", AccountStopoutLevel());
int AccountStopoutMode()
返回止损水平的计算方式,具体如下:
0 —— 以保证金与净值之间的百分比为计算依据;
1 —— 比较可用保证金水平与绝对值。
示例:
int level=AccountStopoutLevel();
if(AccountStopoutMode()==0)
Print("停止水平= ",level, "%");
else
Print("停止水平= ", level, " ", AccountCurrency());
