- 显示:
- 1213
- 等级:
- 已发布:
- 2017.02.07 11:21
-
需要基于此代码的EA交易或指标吗?请在自由职业者服务中订购 进入自由职业者服务
趋势交易系统 Exp_ColorZerolagMomentum_X2, 基于来自来两条 ColorZerolagMomentum 指标的信号。第一个指标基于主线和信号线的位置判断慢性趋势的方向。第二个指标当主线和信号线交叉或接触时判断交易开单的时刻。当柱线收盘时如果满足两个条件, 则形成信号:
- 快速和慢速趋势信号匹配;
- 快速趋势方向已改变。
智能交易系统的输入参数:
//+-------------------------------------------------+
//| EA 指标的输入参数 |
//+-------------------------------------------------+
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; //1 图表趋势周期
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; //2 图表周期
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 指标的输入参数 |
//+-------------------------------------------------+
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; //1 图表趋势周期
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; //2 图表周期
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 代码中, 以便将这些指标包含在交易系统的可执行文件中。
指标可执行文件已作为资源添加到全局范围
//---- 在 EA 代码里包含指标作为资源
#resource "\\Indicators\\ColorZerolagMomentum.ex5"
#resource "\\Indicators\\ColorZerolagMomentum_HTF.ex5"
#resource "\\Indicators\\ColorZerolagMomentum.ex5"
#resource "\\Indicators\\ColorZerolagMomentum_HTF.ex5"
在 OnInit() 函数块里将字符串路径更改为指标的资源
//---- 获取 ColorZerolagMomentum 指标的句柄
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);
}
//---- 获取 ColorZerolagMomentum 指标的句柄
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))
{
//---- 获取 ColorZerolagMomentum_HTF 指标的句柄
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);
}
//---- 获取 ColorZerolagMomentum_HTF 指标的句柄
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);
}
}
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);
}
//---- 获取 ColorZerolagMomentum 指标的句柄
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))
{
//---- 获取 ColorZerolagMomentum_HTF 指标的句柄
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);
}
//---- 获取 ColorZerolagMomentum_HTF 指标的句柄
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. 测试结果图表
由MetaQuotes Ltd译自俄语
原代码: https://www.mql5.com/ru/code/16981