MM % 波动率 - MetaTrader 4脚本
- 显示:
- 6065
- 等级:
- 已发布:
- 2016.05.06 13:38
- 需要基于此代码的EA交易或指标吗?请在自由职业者服务中订购 进入自由职业者服务
参考资产的波动率计算手数比并开仓。止损自动设置, 止盈 - 根据需求, 作为乘数 R。
LotSize:=RiskAmount/(PointPrice*StopLossPoints);
RiskAmount:=FreeMargin*RiskPercent/100;
StopLossPoints:=kATR*ATR(TimeFrame,RiskAtrPeriod)/PointSize;
TakeProfitPoints:=StopLossPoints*ProfitToLossRatio.
操作函数是 Trade, 在 Trade.mq4 库文件里。声明:
int Trade(string smb, int TimeFrame, int cmd, bool ShowQ, int Slippage, bool SetProfit, double MaxRiskPercent, int RiskAtrPeriod, double RiskMulATR, double ProfitToLossRatio), where:
smb - 资产名称;
TimeFrame - 用于检测 StopLossPoints;
cmd - OP_BUY 或 OP_SELL;
ShowQ - 显示确认对话框 (False - 无对话框);
Slippage - 滑点点数;
SetProfit - 若为 True - 将在订单里指定止盈;
MaxRiskPercent - 可用保证金的 %, 允许的风险 (2% - 典型, 5% - 激进, 更高 - 看运气了);
RiskAtrPeriod - 计算真实范围的最后柱线号码 (21 足够了);
RiskMulATR - 用于确定 StopLossPoints;
ProfitToLossRatio - R 的乘数 (例如, 5)。
附带脚本:
Buy.mq4/Sell.mq4 - 买/卖当前资产, 时间帧, 带确认对话框, 滑点 1 个点, 2% 风险, RiskAtrPeriod=21, RiskMulATR=1, ProfitToLossRatio=10;
Buy_nonQuery.mq4/Sell_nonQuery.mq4 - 设置相同, 但没有对话框, 且滑点=0。
如何安装:
Trade.mqh - 拷贝到 MetaTrader 根目录下的 'experts' 目录下的 'include' 子目录;
Trade.mq4 - 拷贝到 MetaTrader 根目录下的 'experts' 目录下的 'libraries' 子目录, 并编译;
Buy.mq4, Buy_nonQuery.mq4, Sell.mq4, Sell_nonQuery.mq4 - 拷贝到 MetaTrader 根目录下的 'experts' 目录下的 'scripts' 子目录, 并编译。
由MetaQuotes Ltd译自俄语
原代码: https://www.mql5.com/ru/code/7387