Optimization Error Please help

 

Hello 

I'm trying to do some calculations with strategy test math calculations. 

Optimization high results do not match re calculated ones. I don't know what is wrong, can someone help me find the error.

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Eq()
  {
   
   for(int i = 0; i < numPatterns; i++)
     {
      sum = 0.0;
      for(int z = 0; z < nINPUT - 1; z++)
        {
         sum += (w[z] * X_[i][z]);
        }
      if(X_[i][nINPUT - 1] == 0)
         if(a(sum) == 1)
            g = g - 9.25;
      if(X_[i][nINPUT - 1] == 1)
         if(a(sum) == 0)
            g = g - 1;
     }
   return(a(sum));
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double a(const double sum_)
  {
   if(sum_ > t)
      return(1);
   else
      return(0);
  }
//+------------------------------------------------------------------+
//| Tester function                                                  |
//+------------------------------------------------------------------+
double OnTester()
  {
   in();
   Eq();
   return(g);
  }
//+------------------------------------------------------------------+

As you can see on the images, the lower results run OK but the maximum one do not