Why isnt my sum working?

 
Hi, ive been trying to compare the current days open to yesturdays close but am a little stuck on the following. 

Can someone please explain to me that within the following code :

//+------------------------------------------------------------------+
// Gap     
//+------------------------------------------------------------------+
void OnTick()
{
   int iBar=Bars-1; // 1000
   string hoursLookBack="";
   int count=1;
   double curOpen=0.0;
   double yesClose=0.0;
   double sumDiffOC=0.0;

   string openTime="16:30";
   string closeTime="23:00";
   
   int barCount=39;

   // Finding AVG Gap
   for(int iEnd = count; iBar >= iEnd; --iBar)    
   { 
      hoursLookBack = TimeToStr(Time[iBar],TIME_MINUTES);
      
      // Records Current Open       
      if(hoursLookBack==openTime) // && iBar<iBarRec
      {
         curOpen=iOpen(_Symbol,_Period,iBar); // Find open at openTime
      }
      
      // Records Yesturdays Close     
      if(hoursLookBack==closeTime)      
      {                                                         
         yesClose=iOpen(_Symbol,_Period,iBar+barCount);
         
         sumDiffOC+=MathAbs(yesClose-curOpen);

         Print(" iBar = ",iBar," yesClose = ",yesClose," curOpen = ",curOpen," sumDiffOC = ",sumDiffOC);
      }   
   }
}

Why is it that when i make barcount = 38 or less sumDiffOC returns a smaller value such as 0.04438999999999993

But when i make barCount = 39 or more sumDiffOC displays a much larger value more closer to a price such as 1.17461

Any help would be very much appreciated

Thanks

 
Stephen Reynol Can someone please explain to me that within the following code
   int iBar=Bars-1; // 1000
   
      hoursLookBack = TimeToStr(Time[iBar],TIME_MINUTES);
You are looking at the oldest bar on the chart.
          date/time (2017)
          Find bar of the same time one day ago - MQL4 programming forum (2017)
 
William Roeder #:
You are looking at the oldest bar on the chart.
          date/time (2017)
          Find bar of the same time one day ago - MQL4 programming forum (2017)

I now see what i was doing wrong.

It was because yesClose was returning 0.0 and so adding the sum wrong to what i intended.

Thanks so much for clearing that up