Need help with MA expert

 
I've been trying to code an expert that buys when the faster MA crosses above the slower MA and sells when it crosses below. The expert enters trades correctly but it won't close a trade and start a new one when the MA's cross. Can someone tell me what I'm doing wrong?
int start() { double MA5C,MA20C,MA5P,MA20P,slip,lot; int total,ticket,cnt; MA5C=iMA(NULL,0,3,-4,MODE_SMMA,PRICE_CLOSE,0); MA20C=iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,0); total=OrdersTotal(); slip=0.00; lot=AccountBalance()/1000; if(total<1) { if((MA5C<MA20C) { ticket=OrderSend(Symbol(),OP_SELL,lot,Bid,10,0,0,0,0,0,Yellow); if(ticket<0) { Print("OrderSend failed with error #",GetLastError()); return(0); } } if(MA5C>MA20C) { ticket=OrderSend(Symbol(),OP_BUY,lot,Ask,10,0,0,0,0,0,Yellow); if(ticket<0) { Print("OrderSend failed with error #",GetLastError()); return(0); } } } for(cnt=0;cnt<total;cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderType()==OP_SELL) { if(MA5C>MA20C) { OrderClose(OrderTicket(),OrderLots(),Ask,10,Green); return(0); } } if(OrderType()==OP_BUY) { if(MA5C<MA20C) { OrderClose(OrderTicket(),OrderLots(),Bid,10,Green); return(0); } } } }

The compiling also says that I have an " 'end_of_program/'-unbalanced left paranthesis" error on the very last line but I can't figure out how to fix it. Any help would be greatly appreciated.
 
Try the following code:
MA5C=iMA(NULL,0,3,-4,MODE_SMMA,PRICE_CLOSE,1); MA20C=iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,1); or MA5C=iMA(NULL,0,3,-4,MODE_SMMA,PRICE_OPEN,0); MA20C=iMA(NULL,0,20,0,MODE_EMA,PRICE_OPEN,0);

---
www.e2e-fx.net
EA development service
 
hey carp, im looking for an exp. m/a ea.  do you have one?
 
carpe193deim wrote:
I've been trying to code an expert that buys when the faster MA crosses above the slower MA and sells when it crosses below. The expert enters trades correctly but it won't close a trade and start a new one when the MA's cross. Can someone tell me what I'm doing wrong?
int start()
  {
  double MA5C,MA20C,MA5P,MA20P,slip,lot;
  int total,ticket,cnt;
  
  MA5C=iMA(NULL,0,3,-4,MODE_SMMA,PRICE_CLOSE,0);
  MA20C=iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,0);
   
  total=OrdersTotal();
  slip=0.00;
  lot=AccountBalance()/1000;
  
  if(total<1)
      {
      if((MA5C<MA20C)
         {
         ticket=OrderSend(Symbol(),OP_SELL,lot,Bid,10,0,0,0,0,0,Yellow);
         if(ticket<0)
            {
            Print("OrderSend failed with error #",GetLastError());
            return(0);
            }       
         }
      if(MA5C>MA20C)
         {
         ticket=OrderSend(Symbol(),OP_BUY,lot,Ask,10,0,0,0,0,0,Yellow);
         if(ticket<0)
            {
            Print("OrderSend failed with error #",GetLastError());
            return(0);
            }       
         }
      }
  for(cnt=0;cnt<total;cnt++)
      {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()==OP_SELL)
         {
        if(MA5C>MA20C) 
            {
            OrderClose(OrderTicket(),OrderLots(),Ask,10,Green); 
            return(0); 
            }
         }
     if(OrderType()==OP_BUY)
         {
        if(MA5C<MA20C) 
            {
            OrderClose(OrderTicket(),OrderLots(),Bid,10,Green); 
            return(0); 
            }
         }
       }
    }

The compiling also says that I have an " 'end_of_program/'-unbalanced left paranthesis" error on the very last line but I can't figure out how to fix it. Any help would be greatly appreciated.
 
I believe you will find that
if((MA5C<MA20C)
is your problem, if you have not already found it..
Reason: