EA not closing open position

 

I am having problems playing around with one of the sample EA's that comes with MT5, the Moving Average EA. I thought I could teach myself mql5 by hacking around with an existing EA.

This is how I have modified the "Check for close position conditions " of the EA by introducing two MAs, where a cross of one MA over the other closes the open position - yeah newbie stuff but you have to start somewhere!

The EA compiles just fine, any ideas why this doesn't close the open position when the MA's cross?

//+------------------------------------------------------------------+
//| Check for close position conditions                              |
//+------------------------------------------------------------------+
void CheckForClose(void)
  {
   MqlRates rt[2];
//--- go trading only for first ticks of new bar
   if(CopyRates(_Symbol,_Period,0,2,rt)!=2)
     {
      Print("CopyRates of ",_Symbol," failed, no history");
      return;
     }
   if(rt[1].tick_volume>1)
      return;
//--- get current Moving Average 
   double   MovingAverageFast[1],MovingAverageSlow[1];
   if((CopyBuffer(ExtHandle,0,0,1,MovingAverageFast)!=1) && (CopyBuffer(ExtHandle1,0,0,1,MovingAverageSlow)!=1))
     {
      Print("CopyBuffer from iMA failed, no data");
      return;
     }
//--- positions already selected before
   bool signal=false;
   long type=PositionGetInteger(POSITION_TYPE);

   if(type==(long)POSITION_TYPE_BUY && MovingAverageFast[0]<MovingAverageSlow[0])
      signal=true;
   if(type==(long)POSITION_TYPE_SELL && MovingAverageFast[0]>MovingAverageSlow[0])
      signal=true;
//--- additional checking
   if(signal)
     {
      if(TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) && Bars(_Symbol,_Period)>100)
         ExtTrade.PositionClose(_Symbol,3);
     }
//---
  }
Files:
 
Attach ( ) full code of the advisor.