Help Needed ("zero divide" error)

 

Can somebody please help me...why i'm getting "zero divide" error when i load that indicator......

int periods = 24;
double buffer_indicador[];
int i;
int maxbars;

int init()
{
   if(IsTesting())
     maxbars = Bars;
        else
          maxbars = 500;
          
        SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,Red);
        SetIndexBuffer(0, buffer_indicador);
        SetLevelValue(0,0.0);
 
        
        return(0);
}

int start()
{
        
        double roc,roc_GBP;     
        int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   
   for(int i=0; i<limit; i++)
   
   {
                                                
                        roc_GBP = ( iClose("GBPJPY", 1, i) - iClose("GBPJPY", 1, periods+i))/ iClose("GBPJPY", 1, periods+i) ;  
                 
              roc = (roc_GBP)*100;
              
                        buffer_indicador[i] = roc;                      
        }

 return(0);
}
 
fx_soul:

Can somebody please help me...why i'm getting "zero divide" error when i load that indicator......

When i equals Bars and then you add periods ( 24 ) to it you will be trying to get the close value for a bar that does not exist, if you do that iClose() will return zero . . . and then you divide by zero. Additionally if you run this on anything other than M1 your Bars value will be wrong . . .
 

thanks for the response Raptor.

so whats the solution how can i write it ? sorry but i'm totally coding noob.

i know it about the m1.

 
fx_soul:

thanks for the response Raptor.

so whats the solution how can i write it ? sorry but i'm totally coding noob.

i know it about the m1.

Talk to the person that wrote it and ask them to fix it. anyone else will have to understand what the Indicator is trying to do and understand the consequences of any changes they make and test what they do . . .
 

i'm trying to wrote that indicator that would simple give me the % change of Gbp/Jpy for the last 24 bars.....

 
fx_soul:

i'm trying to wrote that indicator that would simple give me the % change of Gbp/Jpy for the last 24 bars.....

So it's your code ? well the best way to learn is figure it out and fix it . . . if you don't understand something look it up in the Documentation, Book or search the Forum using Google.
 
thanks raptor
Reason: