Unable to compare with i-lookback value

 

Hello,


I have written an indicator which compares another current indicator candle value to current - lookback indicator candle:

CopyBuffer(Multihandle,0,0,rates_total,handledata);
  int start;
   if(prev_calculated<lookback)
      start=lookback;
   else
      start=prev_calculated-1;
 
     for(int i=start; i<rates_total && !IsStopped(); i++)
     {
         SupportBuffer[i] = (handledata[i]/handledata[i-lookback])*100;
     }
//--- return value of prev_calculated for next call
   return(rates_total);

it is giving divide by 0 error, any idea how to fix the code?

 
Before dividing, you must check if "handledata[i-lookback]" is zero.