求助ea

 

我想做一个EMA4,8交叉的交易系统,但自己才接触ea,编了几次,都以失败告终。

希望版主能帮帮忙,或各位前辈们 写一下源代码 ,不胜感激。

我的目地很简单,金叉多,死叉空,15分钟欧元用。也好以此得个模板仔细研究学习

okillerboy@163.com

 

//+------------------------------------------------------------------+
//| EMA48交叉.mq4 |
//| calvinfx |
//| |
//+------------------------------------------------------------------+
/*
EMA4,8交叉,金叉多,死叉空,15分钟欧元用
*/
#property copyright "calvinfx"
#property link ""
extern double mylots=0.1; //仓位
extern double zisun=100; //止损
extern double ziyin=100; //止盈

int init()
{
return(0);
}
int deinit()
{
return(0);
}
int start()
{
double EMA4_0=iMA(Symbol(),PERIOD_M15,4,0,MODE_EMA,PRICE_CLOSE,0);
double EMA4_1=iMA(Symbol(),PERIOD_M15,4,0,MODE_EMA,PRICE_CLOSE,1);
double EMA8_0=iMA(Symbol(),PERIOD_M15,8,0,MODE_EMA,PRICE_CLOSE,0);
double EMA8_1=iMA(Symbol(),PERIOD_M15,8,0,MODE_EMA,PRICE_CLOSE,1);

if(EMA4_0>EMA8_0&&EMA4_1<EMA8_1) //金叉
{
buy(mylots,zisun,ziyin,"buy",123);
}
if(EMA4_0<EMA8_0&&EMA4_1>EMA8_1) //死叉
{
sell(mylots,zisun,ziyin,"sell",321);
}
return(0);
}
//+------------------------------------------------------------------+

int buy(double lots,int zisun,int ziyin,string comment,int magic)
{
int kaiguan=0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES )==true)
{
if(OrderComment()==comment&&OrderMagicNumber()==magic)
{
kaiguan=1;
}
}
}
if(kaiguan==0)
{
OrderSend(Symbol(),OP_BUY,lots,Ask,30,Ask-zisun*Point,Ask+ziyin*Point,comment,magic,0,Blue);
}
return(0);
}

int sell(double lots,int zisun,int ziyin,string comment,int magic)
{
int kaiguan=0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES )==true)
{
if(OrderComment()==comment&&OrderMagicNumber()==magic)
{
kaiguan=1;
}
}
}
if(kaiguan==0)
{
OrderSend(Symbol(),OP_SELL,lots,Bid,30,Bid+zisun*Point,Bid-ziyin*Point,comment,magic,0,Red);
}
return(0);
}