MQL4: 雙重時間框架雙均線交易系統

1、交易策略ui

2、EA源碼code

//+------------------------------------------------------------------+
//|                                                myEA20180104.mq4 |
//|                                                Copyright 2017,CuiYi |
//|                                                010333562@qq.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017,CuiYi"
#property link      "1010333562@qq.com"
#property version   "1.00"
#property stric
#define MAGICMA 19880305

extern double Lots=0.01;

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,maA,maB;
	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,240,10,6,MODE_EMA,PRICE_CLOSE,0);
	ma4=iMA(NULL,240,20,6,MODE_EMA,PRICE_CLOSE,0);
	
	maA=iMA(NULL,30,10,6,MODE_EMA,PRICE_CLOSE,1);
	maB=iMA(NULL,30,20,6,MODE_EMA,PRICE_CLOSE,1);
	
	if(ma1>ma2 && maA<maB && ma3>ma4)
		{
		res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"",MAGICMA,0,Blue);
		return;
		}
	
	if(ma1<ma2 && maA>maB && ma3<ma4)
		{
		res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"",MAGICMA,0,Red);
		return;
		}
	}

void CheckForClose()
	{
	double ma1,ma2,ma3,ma4,maA,maB;
		
	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,240,10,6,MODE_EMA,PRICE_CLOSE,0);
	ma4=iMA(NULL,240,20,6,MODE_EMA,PRICE_CLOSE,0);
	
	maA=iMA(NULL,30,10,6,MODE_EMA,PRICE_CLOSE,1);
	maB=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 && maA>maB && ma3>ma4)	
			OrderClose(OrderTicket(),Lots,Bid,3,White);
			break;
			}
			
		if(OrderType()==OP_SELL)
			{
			if(ma1>ma2 && maA<maB && ma3<ma4)	
			OrderClose(OrderTicket(),Lots,Bid,3,White);
			break;
			}
		}
	}	

void start()
	{
	if(Bars<100 || IsTradeAllowed()==false) return;
	if(CalculateCurrentOrder(Symbol())==0) CheckForOpen();
	else CheckForClose();
	}

3、系統回測圖片

1.EUR/USD源碼

回測時間:2017/01/01 - 2018/01/01string

時間週期:M30it

淨值圖:io

輸入圖片說明

回測報告:im

輸入圖片說明

相關文章
相關標籤/搜索