下载MetaTrader 5

请教如何获取当前账户净值和浮亏

要添加评论,请登录注册
使用口袋粘贴您的内容。非常方便!
king1898
243
king1898 2014.03.22 04:17 

请问是否有内置函数类似PositionGetDouble(POSITION_PROFIT)直接得到净值和亏损,

当浮亏达到10%,则止损,

还是要使用其他标准类里的函数,请指教! 

Jinsong Zhang
15600
Jinsong Zhang 2014.03.23 04:13  
Documentation on MQL5: Account Information / AccountInfoDouble
Documentation on MQL5: Account Information / AccountInfoDouble
  • www.mql5.com
Account Information / AccountInfoDouble - Documentation on MQL5
king1898
243
king1898 2014.03.24 14:56  

非常感谢

Yongbiao Zou
2581
Yongbiao Zou 2014.03.24 15:10  
king1898:

请问是否有内置函数类似PositionGetDouble(POSITION_PROFIT)直接得到净值和亏损,

当浮亏达到10%,则止损,

还是要使用其他标准类里的函数,请指教! 

 

Yongbiao Zou
2581
Yongbiao Zou 2014.03.24 15:10  
kpdabiao:

void OnStart()
  {
//--- show all the information available from the function AccountInfoDouble()
   printf("ACCOUNT_BALANCE =  %G",AccountInfoDouble(ACCOUNT_BALANCE));
   printf("ACCOUNT_CREDIT =  %G",AccountInfoDouble(ACCOUNT_CREDIT));
   printf("ACCOUNT_PROFIT =  %G",AccountInfoDouble(ACCOUNT_PROFIT));
   printf("ACCOUNT_EQUITY =  %G",AccountInfoDouble(ACCOUNT_EQUITY));
   printf("ACCOUNT_MARGIN =  %G",AccountInfoDouble(ACCOUNT_MARGIN));
   printf("ACCOUNT_FREEMARGIN =  %G",AccountInfoDouble(ACCOUNT_FREEMARGIN));
   printf("ACCOUNT_MARGIN_LEVEL =  %G",AccountInfoDouble(ACCOUNT_MARGIN_LEVEL));
   printf("ACCOUNT_MARGIN_SO_CALL = %G",AccountInfoDouble(ACCOUNT_MARGIN_SO_CALL));
   printf("ACCOUNT_MARGIN_SO_SO = %G",AccountInfoDouble(ACCOUNT_MARGIN_SO_SO));
  }

king1898
243
king1898 2014.03.26 04:41  

那怎么计算当前的净值最大还能买卖多少手呢? 谢谢

Jian Chen
版主
3620
Jian Chen 2014.04.09 15:55  
king1898:

那怎么计算当前的净值最大还能买卖多少手呢? 谢谢

可以参考"Moving Average.mq5" 中的代码

//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double TradeSizeOptimized(void)
  {
   double price=0.0;
   double margin=0.0;
//--- select lot size
   if(!SymbolInfoDouble(_Symbol,SYMBOL_ASK,price))
      return(0.0);
   if(!OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,1.0,price,margin))
      return(0.0);
   if(margin<=0.0)
      return(0.0);

   double lot=NormalizeDouble(AccountInfoDouble(ACCOUNT_FREEMARGIN)*MaximumRisk/margin,2);

// 此处忽略了一些代码 ...

//--- normalize and check limits
   double stepvol=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
   lot=stepvol*NormalizeDouble(lot/stepvol,0);

   double minvol=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
   if(lot<minvol)
      lot=minvol;

   double maxvol=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX);
   if(lot>maxvol)
      lot=maxvol;
//--- return trading volume
   return(lot);
  }

 以上代码是复制来的,我删除了一部分,"MaximumRisk" 是一个输入参数,如果你要看最多能买多少手,就用100代替

要添加评论,请登录注册