SafeDivide
- division with divide-by-zero protection

Math functions
(AmiBroker 6.40)


SYNTAX SafeDivide( x, y, valueifzerodiv )
RETURNS NUMBER or ARRAY
FUNCTION Safe division that handles division by zero using special handling (replace result with user-defined value)

Parameters:

  • x - dividend
  • y - divisor
  • valyeifzerodiv - the value that is returned by the function if divisor (y) is equal zero
The function returns the value of x / y ( x divided by y ) as long as y != 0. If y == 0 the value specified in valyeifzerodiv argument is returned. Since AmiBroker 6.90 valyeifzerodiv might be an array.
EXAMPLE // normal division by (High - Low) can result in division by zero error
// but this will safely return 0 on days when high == low
result = SafeDivide( Close - Low, High - Low, 0 );
SEE ALSO

References:

The SafeDivide function is used in the following formulas in AFL on-line library:

More information:

See updated/extended version on-line.