extern double lots = 1.0;
extern double sl =55;
extern double tp =55;
extern double trailing =20;
extern int MaxOrder =1;
int start()
{
if(OrdersTotal()<MaxOrder)
{
double var1 = 0.00015;
double var2 = 0.00000;
double ma1 =iMA(NULL,0,5,0,MODE_SMMA,PRICE_MEDIAN,0);
double ma2 =iMA(NULL,0,15,0,MODE_SMMA,PRICE_MEDIAN,0);
double min = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
double sig = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
if ((ma2-var2>=ma1))
{
if ((sig-var1)>=min)
{OrderSend(Symbol(),OP_SELL,lots,Bid,3,Bid+Point*sl,Bid-Point*tp,"EA Creator",123,0,Red); }
}
if ((ma2+var2<=ma1))
{
if ((sig+var1)<=min)
{OrderSend(Symbol(),OP_BUY,lots,Ask,3,Ask-Point*sl,Ask+Point*tp,"EA Creator",123,0,Green);}
}
trailingstop();
}
return(0) ;
}
void trailingstop() {
for(int count=0;count<OrdersTotal();count++)
{OrderSelect(count,SELECT_BY_POS,MODE_TRADES);
if(OrderType() == OP_BUY)
{if(trailing > 0){
if(Bid - OrderOpenPrice() > trailing*Point)
{if(OrderStopLoss()==0 || (Bid - OrderStopLoss()> trailing*Point))
{OrderModify(OrderTicket(), OrderOpenPrice(),Bid - trailing*Point, OrderTakeProfit(), 0, Blue); }
}
}
}
if(OrderType() == OP_SELL)
{ if(trailing > 0)
{if(OrderOpenPrice() - Ask > trailing*Point)
{
if(OrderStopLoss() == 0 || ( OrderStopLoss()-Ask > trailing*Point ) )
{OrderModify(OrderTicket(), OrderOpenPrice(),Ask + trailing*Point, OrderTakeProfit(), 0, Red); }
}
}
}
}
}