一、交易策略
入场原则:
做多入场:30分钟图上10周期EMA向上交叉20周期EMA 做空入场:30分钟图上10周期EMA向下交叉20周期EMA
出场原则:
做多出场:30分钟图上10周期EMA向下交叉20周期EMA 做空出场:30分钟图上10周期EMA向上交叉20周期EMA![]
二、EA源码
//+------------------------------------------------------------------+
//| myEA20180104.mq4 |
//| Copyright 2017,CuiYi |
//| 1010333562@qq.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017,CuiYi"
#property link "1010333562@qq.com"
#property version "1.00"
#property strict
#define MAGICMA 19880305
extern double Lots=1;
int CalculateCurrentOrder(string symbol)
{
int buys=0,sells=0;
for(int i=0;i<OrdersTotal();i=i+1)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
}
if(buys>0) return(buys);
else return(-sells);
}
void CheckForOpen()
{
double ma1,ma2,ma3,ma4;
int res;
ma1=iMA(NULL,30,10,6,MODE_EMA,PRICE_CLOSE,0);
ma2=iMA(NULL,30,20,6,MODE_EMA,PRICE_CLOSE,0);
ma3=iMA(NULL,30,10,6,MODE_EMA,PRICE_CLOSE,1);
ma4=iMA(NULL,30,20,6,MODE_EMA,PRICE_CLOSE,1);
if(ma1>ma2 && ma3<ma4)
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"",MAGICMA,0,Blue);
return;
}
if(ma1<ma2 && ma3>ma4)
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"",MAGICMA,0,Red);
return;
}
}
void CheckForClose()
{
double ma1,ma2,ma3,ma4;
ma1=iMA(NULL,30,10,6,MODE_EMA,PRICE_CLOSE,0);
ma2=iMA(NULL,30,20,6,MODE_EMA,PRICE_CLOSE,0);
ma3=iMA(NULL,30,10,6,MODE_EMA,PRICE_CLOSE,1);
ma4=iMA(NULL,30,20,6,MODE_EMA,PRICE_CLOSE,1);
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
if(OrderType()==OP_BUY)
{
if(ma1<ma2 && ma3>ma4)
OrderClose(OrderTicket(),Lots,Bid,3,White);
break;
}
if(OrderType()==OP_SELL)
{
if(ma1>ma2 && ma3<ma4)
OrderClose(OrderTicket(),Lots,Bid,3,White);
break;
}
}
}
void start()
{
if(Bars<100 || IsTradeAllowed()==false) return;
if(CalculateCurrentOrder(Symbol())==0) CheckForOpen();
else CheckForClose();
}
三、系统回测
1.EUR/USD
回测时间:2017/01/01 - 2018/01/01
时间周期:M30
净值图:
回测报告:
20180204更新:
//+------------------------------------------------------------------+
//| 5&15min双均线交易.mq4 |
//| Copyright 2018,CuiYi |
//| 1010333562@qq.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018,CuiYi"
#property link "1010333562@qq.com"
#property version "1.00"
#property strict
#define MAGICMA 19880305
extern double Lots=0.08;
int CalculateCurrentOrder(string symbol)
{
int buys=0,sells=0;
for(int i=0;i<OrdersTotal();i=i+1)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
}
if(buys>0) return(buys);
else return(-sells);
}
void CheckForOpen()
{
double ma1,ma2,ma3,ma4;
int res;
ma1=iMA(NULL,30,9,1,MODE_EMA,PRICE_CLOSE,1);
ma2=iMA(NULL,30,18,1,MODE_EMA,PRICE_CLOSE,1);
ma3=iMA(NULL,15,9,1,MODE_EMA,PRICE_CLOSE,1);
ma4=iMA(NULL,15,18,1,MODE_EMA,PRICE_CLOSE,1);
if(ma1>ma2 && ma3>ma4)
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"",MAGICMA,0,Blue);
return;
}
if(ma1<ma2 && ma3<ma4)
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"",MAGICMA,0,Red);
return;
}
}
void CheckForClose()
{
double ma1,ma2,ma3,ma4;
ma1=iMA(NULL,30,9,1,MODE_EMA,PRICE_CLOSE,1);
ma2=iMA(NULL,30,18,1,MODE_EMA,PRICE_CLOSE,1);
ma3=iMA(NULL,15,9,1,MODE_EMA,PRICE_CLOSE,1);
ma4=iMA(NULL,15,18,1,MODE_EMA,PRICE_CLOSE,1);
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()==MAGICMA || OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
{
if(ma3<ma4)
{
if(!OrderClose(OrderTicket(),Lots,Bid,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
if(OrderType()==OP_SELL)
{
if(ma3>ma4)
{
if(OrderClose(OrderTicket(),Lots,Ask,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
}
}
}
void start()
{
if(Bars<100 || IsTradeAllowed()==false) return;
if(CalculateCurrentOrder(Symbol())==0) CheckForOpen();
else CheckForClose();
}
20180205更新:
//+------------------------------------------------------------------+
//| 15min均线交易.mq4 |
//| Copyright 2018,CuiYi |
//| 1010333562@qq.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018,CuiYi"
#property link "1010333562@qq.com"
#property version "1.00"
#property strict
#define MAGICMA 19880305
extern double Lots=0.08;
int CalculateCurrentOrder(string symbol)
{
int buys=0,sells=0;
for(int i=0;i<OrdersTotal();i=i+1)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
}
if(buys>0) return(buys);
else return(-sells);
}
void CheckForOpen()
{
double ma1,ma2;
int res;
ma1=iMA(NULL,15,9,1,MODE_EMA,PRICE_CLOSE,1);
ma2=iMA(NULL,15,18,1,MODE_EMA,PRICE_CLOSE,1);
if(ma1>ma2)
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"",MAGICMA,0,Blue);
return;
}
if(ma1<ma2)
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"",MAGICMA,0,Red);
return;
}
}
void CheckForClose()
{
double ma3,ma4;
ma3=iMA(NULL,15,9,1,MODE_EMA,PRICE_CLOSE,1);
ma4=iMA(NULL,15,18,1,MODE_EMA,PRICE_CLOSE,1);
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()==MAGICMA || OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
{
if(ma3<ma4)
{
if(!OrderClose(OrderTicket(),Lots,Bid,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
if(OrderType()==OP_SELL)
{
if(ma3>ma4)
{
if(OrderClose(OrderTicket(),Lots,Ask,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
}
}
}
void start()
{
if(Bars<100 || IsTradeAllowed()==false) return;
if(CalculateCurrentOrder(Symbol())==0) CheckForOpen();
else CheckForClose();
}