请问是否有 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.
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、
首先,您必须在 EA 中添加 2 个输入:
bool UseMaximumPercentageRisk=true; double MaximumPercentageRisk=25;
然后,您必须调用函数 GetLots() 并在括号中设置您希望的手数,例如调用:
double MyLotSize; MyLotSize = GetLots (100);
根据您输入的最大百分比风险(MaximumPercentageRisk)和账户净值,您将获得正确的手数。
例如,如果MaximumPercentageRisk = 1;,而您的净值 = 1000$,函数将返回 0.01 lot。
低风险交易,市场其实很狂野;-)
嗨,感谢您分享这些信息。
我是个菜鸟,但我很希望能有一种方法使我的手数大小保持一致,我想知道如何使用您的代码来做到这一点?
非常感谢
例如,如果MaximumPercentageRisk = 1;,而您的净值 = 1000$,函数将返回 0.01 lot。
低风险交易,市场其实很狂野;-)
, 我以为您的目的是根据您选择的风险和当前账户余额获得适当的手数。
,如果您能稍作说明,我将不胜感激。谢谢
依据净值百分比计算最大风险:
作者: Remi PASSANELLO