Warning 505. Division by zero

Your formula is doing division and the divisor (denominator) is zero. The result of such expression is either infinity or Nan (not a number). If denominator is an array, this warning message means that one of denominator array elements is zero.


There are many ways to prevent this, namely:

1. Checking denominator for zero prior to division and avoid division in such cases (works for scalars, not arrays):

for( i = 0; i < BarCount; i++ )
{
   denom = High[ i ] - Low[ i ];
  
   if( denom != 0 ) result[ i ] = Close[ i ] / denom; // only divide when denominator is not zero
}

2. Adding small value to denominator (works for both scalars and arrays)

result = Close / ( High - Low + 1e-9 );

3. Using Nz() function to convert non-a-numbers and infinites to resonable value (by default zero). Note that this won't supress the warning but will make the result finite:

result = Nz( Close / ( High - Low ) );

4. Changing zero values in denominator array prior to division using IIF() function

denom = High - Low;
result = Close / IIf( denom != 0, denom, 0.001 );