MA Cross Over HELP on EA

 
I'm pulling my hair out and need some help.

The attached EA is just a very simple one and is producing signals, but the orders are not being entered and NO ERRORS are showing up in the Journal.

What it should do is every time the current price crosses UP or DOWN on the EMA 89 it would place an order in the direction of the cross.

It places the first one then no more orders.

You can see in the Journal there are plenty of signals being triggered when you run it.

PLEASE HELP!

Thanks in advance.
Neal

//+------------------------------------------------------------------+
//|                                                 Daily 100 System |
//|                                   Copyright © 2008, Neal Chapman |
//|                                                nealc99@gmail.com |
//+------------------------------------------------------------------+


//---- input parameters
extern int        MagicNumber = 304323;
extern int        StopLoss=30;
extern int        TakeProfit=40;
extern double     Lots=1;
int               Bought=0;
int               Ticket,OrderSignal=0;
double            EMA89,pbid;
double            Vol;

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+

int start()
  {
   //---- 
      
      EMA89 = iMA(NULL, 15, 89, 0, MODE_SMA, PRICE_MEDIAN, 0);
         
      if ((Close[0] >= EMA89) && (Close[1] >= EMA89) && (Open[2] < EMA89)) {
         OrderSignal=1;
         //--------------------------------
         // BEGIN - this IF statement only for debug purposes
         //-------------------------
         if(EMA89 != pbid)
         {
            Print("Buy Ready >>>> H: ",Open[0]," >(1)H: ",Close[1]," (89): ",EMA89," <(2)L: ",Open[2]," Signal: ",OrderSignal);
            pbid=EMA89;
         }
         //--------------------------------
         // END - this IF statement only for debug purposes
         //-------------------------
      }else if ((Close[0] <= EMA89) && (Close[1] <= EMA89) && (Open[2] > EMA89)) {
          OrderSignal=-1;
         //--------------------------------
         // BEGIN - this IF statement only for debug purposes
         //-------------------------
         if(EMA89 != pbid)
         {
          Print("Sell Ready >>>> L: ",Open[0]," >(1)L: ",Close[1]," (89): ",EMA89," <(2)H: ",Open[2]," Signal: ",OrderSignal);
          pbid=EMA89;
          }
         //--------------------------------
         // END - this IF statement only for debug purposes
         //-------------------------
      }else{
         OrderSignal=0;
      }

   
      //Check to see if there is an order currently open
      int cnt, total = OrdersTotal();

      for(cnt=0;cnt<total;cnt++)
      {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if(OrderMagicNumber() == MagicNumber)
            Bought++;
       }
   
      if(Bought==0){ //no order yet
         if(OrderSignal > 0){ // buy order
            Vol=Lots;
            Ticket=OrderSend(Symbol(),OP_BUY,Vol,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"Daily100",MagicNumber,0,Green);
         }
         if(OrderSignal < 0){ // sell order
            Vol=Lots;
            Ticket=OrderSend(Symbol(),OP_SELL,Vol,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"Daily100",MagicNumber,0,Red);
         }
      }

   return(0);
   }

 
      for(cnt=0;cnt<total;cnt++)
      {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if(OrderMagicNumber() == MagicNumber)
            Bought++;
       }

      if(Bought==0){ //no order yet
         if(OrderSignal > 0){ // buy order
            Vol=Lots;
            Ticket=OrderSend(Symbol(),OP_BUY,Vol,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"Daily100",MagicNumber,0,Green);
         }
         if(OrderSignal < 0){ // sell order
            Vol=Lots;
            Ticket=OrderSend(Symbol(),OP_SELL,Vol,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"Daily100",MagicNumber,0,Red);
         }
      }



After your first order, Bought is incremented on each tick, as the magic number is found in the order pool.

Therefore, Bought no longer is equal to 0.

Then what?

Reason: