Problem with MACD EA

 

Hi dear community, i would like to assist me in finding if anything is wrong with my code.

I'm coding a MACD EA, basically it works how it supposed to be (the Logic), but when you test it, you realize that some signals are being ignored.

To be precise, 80% of the MACD signals are well trades, however 10% are ignored and the other 10% are traded in the wrong direction. 

// MACD settings
input int FastEMA = 12;
input int SlowEMA = 26;
input int SignalSMA = 9;
input int AppliedPrice = PRICE_CLOSE;


int macd_handle;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   macd_handle = iMACD(Symbol(), 0, FastEMA, SlowEMA, SignalSMA, AppliedPrice);
   if(macd_handle == INVALID_HANDLE)
     {
      Print("Error creating MACD indicator handle: ", GetLastError());
      return(INIT_FAILED);
     }
   return(INIT_SUCCEEDED);
  }


//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   IndicatorRelease(macd_handle);
  }


//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   double macd_main[];
   double macd_signal[];
   ArraySetAsSeries(macd_main, true);
   ArraySetAsSeries(macd_signal, true);
   CopyBuffer(macd_handle, 0, 0, 2, macd_main);
   CopyBuffer(macd_handle, 1, 0, 2, macd_signal);

   if(macd_main[0] > macd_signal[0] && macd_main[1] < macd_signal[1]) // Buy condition
     {
 // Open Buy
     }
   else if(macd_main[0] < macd_signal[0] && macd_main[1] > macd_signal[1]) // Sell condition
     {
 // Open Sell
     }
  }

Here are two screenshots as examples.