资料库: 依据净值百分比计算最大风险

 

依据净值百分比计算最大风险:

这段代码允许您设置依据净值百分比计算的最大风险。

作者: Remi PASSANELLO

 
请问是否有 MQL4 版本?
 
Roszey:
请问是否有 MQL4 版本?
bool UseMaximumPercentageatRisk = true;
double MaximumPercentageatRisk =1;
bool IsMicroAccount = true ; //for accounts allowing 0.01 lots
double GetLots(double lotsize_bn)
  {

   int tmpdecimal=1;
   if(IsMicroAccount)
     {
      tmpdecimal=2;
     }
   double old_lot=lotsize_bn;
   if((NormalizeDouble(AccountFreeMargin()*(MaximumPercentageatRisk/100)/1000.0,tmpdecimal)<lotsize_bn) && UseMaximumPercentageatRisk)
     {
      lotsize_bn=NormalizeDouble(AccountFreeMargin()*(MaximumPercentageatRisk/100)/1000.0,tmpdecimal);
      if(lotsize_bn<MarketInfo(Symbol(),MODE_MINLOT))
        {
         lotsize_bn=MarketInfo(Symbol(),MODE_MINLOT);
         Print("RPTrade-Lot adjusted from ",old_lot," to minimum size allowed by the server of ",lotsize_bn," but it DOES NOT comply with Maximum Risk condition. User interaction is required!");
        }
      else
        {
         Print("RPTrade-Lot adjusted from ",old_lot," to ",lotsize_bn," to comply with Maximum Risk condition. Each trade can risk only ",MaximumPercentageatRisk,"% of free margin.");
        }
     }
   return (lotsize_bn);
  }

应该是这样的;-)

R.

 
您能告诉我如何将其附加到 EA 中吗?
 

I was looking at your code in MQL5 for "Maximum Percentage of Equity Risk". 
I have some doubts regarding to how to use it. I have the mqh file in the include file and use #include <RPTrade.mqh> at the expert that I want to use. 
Can you elaborate more on how to use this code in a expert advisor please? I'm new to coding. I have made expert advisors, but I don't know how to call a class or function in another file.

我需要调用函数 GetLots (lotsize) 对吗?在我的订单请求中,地段需要使用 "lotize "值吗?

谢谢!

 
patagonia2015:

你好,Patagonia2015、

首先,您必须在 EA 中添加 2 个输入:

bool 	 UseMaximumPercentageRisk=true;
double 	 MaximumPercentageRisk=25;

然后,您必须调用函数 GetLots() 并在括号中设置您希望的手数,例如调用:

double  MyLotSize;
MyLotSize = GetLots (100);

根据您输入的最大百分比风险(MaximumPercentageRisk)和账户净值,您将获得正确的手数。

例如,如果MaximumPercentageRisk = 1;,而您的净值 = 1000$,函数将返回 0.01 lot。

低风险交易,市场其实很狂野;-)

 

嗨,感谢您分享这些信息。

我是个菜鸟,但我很希望能有一种方法使我的手数大小保持一致,我想知道如何使用您的代码来做到这一点?

非常感谢

 
Remi Passanello 账户净值,您将获得正确的手数。

例如,如果MaximumPercentageRisk = 1;,而您的净值 = 1000$,函数将返回 0.01 lot。

低风险交易,市场其实很狂野;-)

对不起,您说"您必须调用函数 GetLots() 并在括号中设置您希望的手数 " 时有点让我困惑,

以为您的目的是根据您选择的风险和当前账户余额获得适当的手数。

,如果您能稍作说明,我将不胜感激。谢谢
 
Muhammad Shamsuddeen Muhammad #:
对不起,您说"您必须调用函数 GetLots() 并在括号中设置您希望的手数",这 有点让我困惑

,我以为您的目的是根据您选择的风险和当前账户余额获得适当的手数。 ,如果您能稍加说明,将不胜感激。谢谢

我也是这么想的