Zero Divided Message

 

Hello,

I have created a function to calculate the price´s changing rate. 

double Delta(const double &buffer1[],const double &buffer2[], int N, int index )
{
 double var=0.0; 
var = ((buffer1[index]-buffer1[index-N])/buffer2[index-N]) ;

 return 100*var;
 }

but depending on the the buffer that I use to parameter "buffer2[index-N]", the compiler shows the message : " zero divided on Delta".

So I modified the previous function to:


double Delta(const double &buffer1[],const double &buffer2[], int N, int index )
{
 double var=0.0;
 
 if(buffer2[index-N]==0)
 buffer2[index-N]==1;
 else
 buffer2[index-N]== buffer2[index-N];

 var = ((buffer1[index]-buffer1[index-N])/buffer2[index-N]) ;

 return 100*var;
 }

But it is not working....


Some thoughts?

Thank you all

 
Pedro Henrique Vieira:

Hello,

I have created a function to calculate the price´s changing rate. 

but depending on the the buffer that I use to parameter "buffer2[index-N]", the compiler shows the message : " zero divided on Delta".

So I modified the previous function to:


But it is not working....


Some thoughts?

Thank you all

change to that.

 if(buffer2[index-N]==0)
 buffer2[index-N]=1;
 else
 buffer2[index-N]= buffer2[index-N];
 
Janfi-trading:

change to that.



Unfortunately it does not work.

The message :'buffer2' - constant cannot be modified


 
Pedro Henrique Vieira:



Unfortunately it does not work.

The message :'buffer2' - constant cannot be modified


I made it two versions, one for OHCL informations that requires parameter of type "const double" and another to ohter Buffers that does not.

Reason: