趋势交易系统 Exp_ColorZerolagMomentum_X2, 基于来自来两条
ColorZerolagMomentum 指标的信号。第一个指标基于主线和信号线的位置判断慢性趋势的方向。第二个指标当主线和信号线交叉或接触时判断交易开单的时刻。当柱线收盘时如果满足两个条件, 则形成信号:
快速和慢速趋势信号匹配;
快速趋势方向已改变。
智能交易系统的输入参数:
input string Trade="交易管理";
input double MM=0.1;
input MarginMode MMMode=LOT;
input uint StopLoss_=1000;
input uint TakeProfit_=2000;
input string MustTrade="交易许可";
input int Deviation_=10;
input bool BuyPosOpen=true;
input bool SellPosOpen=true;
input string Filter="慢速趋势参数";
input ENUM_TIMEFRAMES TimeFrame=PERIOD_H6;
input uint smoothing=15;
input ENUM_APPLIED_PRICE IPC=PRICE_CLOSE;
input double Factor1=0.05;
input uint Momentum_period1=8;
input double Factor2=0.10;
input uint Momentum_period2=21;
input double Factor3=0.16;
input uint Momentum_period3=34;
input double Factor4=0.26;
input int Momentum_period4=55;
input double Factor5=0.43;
input uint Momentum_period5=89;
input uint SignalBar=1;
input bool BuyPosClose=true;
input bool SellPosClose=true;
input string Input="入场参数";
input ENUM_TIMEFRAMES TimeFrame_=PERIOD_M30;
input uint smoothing_=15;
input ENUM_APPLIED_PRICE IPC_=PRICE_CLOSE;
input double Factor1_=0.05;
input uint Momentum_period1_=8;
input double Factor2_=0.10;
input uint Momentum_period2_=21;
input double Factor3_=0.16;
input uint Momentum_period3_=34;
input double Factor4_=0.26;
input int Momentum_period4_=55;
input double Factor5_=0.43;
input uint Momentum_period5_=89;
input uint SignalBar_=1;
input bool BuyPosClose_=false;
input bool SellPosClose_=false;
字符串参数与输入参数代码中的文本仅为 EA 的输入参数窗口更直观。
EA 中的 ColorZerolagMomentum_HTF 指标只是出于更方便地在策略测试器中将趋势可视化, 在其它操作模式中它们没有动作。
放置 ColorZerolagMomentum.ex5 和 ColorZerolagMomentum_HTF.ex5 编译文件至 <客户端文件夹>\MQL5\Indicators。
编译之后, Exp_ColorZerolagMomentum.ex5 交易系统文件将 ColorZerolagMomentum.ex5 和 ColorZerolagMomentum_HTF.ex5 指标作为 资源 包含在内, 所以, 编译 EA 时不需要它们出现在终端文件夹里即可工作!为此目的, 已将相应的代码添加到 EA 代码中, 以便将这些指标包含在交易系统的可执行文件中。
指标可执行文件已作为资源添加到全局范围
#resource "\\Indicators\\ColorZerolagMomentum.ex5"
#resource "\\Indicators\\ColorZerolagMomentum_HTF.ex5"
在 OnInit() 函数块里将字符串路径更改为指标的资源
InpInd_Handle=iCustom(Symbol(),TimeFrame,"::Indicators\\ColorZerolagMomentum",
smoothing,IPC,Factor1,Momentum_period1,Factor2,Momentum_period2,Factor3,Momentum_period3,Factor4,Momentum_period4,Factor5,Momentum_period5);
if(InpInd_Handle==INVALID_HANDLE)
{
Print(" 获取 ColorZerolagMomentum 指标句柄失败");
return(INIT_FAILED);
}
InpInd_Handle_=iCustom(Symbol(),TimeFrame_,"::Indicators\\ColorZerolagMomentum",
smoothing_,IPC_,Factor1_,Momentum_period1_,Factor2_,Momentum_period2_,Factor3_,Momentum_period3_,Factor4_,Momentum_period4_,Factor5_,Momentum_period5_);
if(InpInd_Handle_==INVALID_HANDLE)
{
Print(" 获取 ColorZerolagMomentum 指标句柄失败");
return(INIT_FAILED);
}
if(MQLInfoInteger(MQL_VISUAL_MODE))
{
int Ind_Handle=iCustom(Symbol(),Period(),"::Indicators\\ColorZerolagMomentum_HTF",TimeFrame,
smoothing,IPC,Factor1,Momentum_period1,Factor2,Momentum_period2,Factor3,Momentum_period3,Factor4,Momentum_period4,Factor5,Momentum_period5);
if(Ind_Handle==INVALID_HANDLE)
{
Print(" 获取 ColorZerolagMomentum_HTF 指标句柄失败");
return(INIT_FAILED);
}
Ind_Handle=iCustom(Symbol(),Period(),"::Indicators\\ColorZerolagMomentum_HTF",TimeFrame_,
smoothing_,IPC_,Factor1_,Momentum_period1_,Factor2_,Momentum_period2_,Factor3_,Momentum_period3_,Factor4_,Momentum_period4_,Factor5_,Momentum_period5_);
if(Ind_Handle==INVALID_HANDLE)
{
Print(" 获取 ColorZerolagMomentum_HTF 指标句柄失败");
return(INIT_FAILED);
}
}
因此, 已编译的交易系统可执行文件能够在其它交易终端上独自使用, 而无需指标。
注意,如果交易商提供非零点差,并且可在开仓时设置止损及止盈,这个 TradeAlgorithms.mqh 库文件方可在 EA 中使用。您可以下载更多库文件的变体,链接如下: 交易算法。
在测试时使用的省缺自动交易程序的输入参数如下所示。止损和止盈测试中未使用。

图例. 1. 图表中是交易例子
测试结果 2015 品种 GBPJPY, 慢速趋势 H6, 入场依据快速趋势 M30:

图例. 2. 测试结果图表