//+------------------------------------------------------------------+
//| crossover.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
extern int Timeframe=15;
extern double Lots=0.01;
extern int SL=25;
extern int ema5_shift=1;
extern int ema20_shift=1;
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
double ema5=iMA(Symbol(),Timeframe,5,0,1,0,ema5_shift);
double ema5s=iMA(Symbol(),Timeframe,5,0,1,0,ema5_shift+1);
double ema20=iMA(Symbol(),Timeframe,20,0,1,0,ema20_shift);
double ema20s=iMA(Symbol(),Timeframe,20,0,1,0,ema20_shift+1);
if(OrdersTotal()==0 && ema5s<ema20s && ema5>ema20)
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,LongSL(),0,NULL,0,0,Blue);
}
if(OrdersTotal()==0 && ema5s>ema20s && ema5<ema20)
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,ShortSL(),0,NULL,0,0,Red);
}
if(OrdersTotal()>0)
{
for(int i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY && ema5<ema20)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Black);
}
if(OrderType()==OP_SELL && ema5>ema20)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Black);
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
double LongSL()
{
if(SL==0){return(0);}
if(SL>0){return(Bid-SL*Point);}
}
double ShortSL()
{
if(SL==0){return(0);}
if(SL>0){return(Ask+SL*Point);}
}