FindIndex
- find index of array item matching specified value

Miscellaneous functions
(AmiBroker 6.40)


SYNTAX FindIndex( array, value, start_from = 0, dir = 1 )
RETURNS NUMBER
FUNCTION Find an index of array item matching specified value

Returns:
NUMBER - the index of matching array item if value is not found in the array, the function returns -1

Parameters:

  • array - input data
  • value - what we are looking for
  • start - the index to start the search from
  • dir - the direction of the search, 1 is up, -1 is down

    Notes: start can be positive - then it refers to index number counting from the beginning of array or it can be negative then it refers to index counting from the END of the array

EXAMPLE // example find all indices when condition was true

condition = Cross( C, MA( C, 20 ) );

// search forwards
printf("Search forwards:\n");
for( index = 0; ( index = FindIndex( condition, True, index ) ) != -1; index++ )
{
   printf("condition is true at index %g\n", index );
}

// search backwards
printf("Search backwards:\n");
for( index = -1; ( index = FindIndex( condition, True, index, -1 ) ) != -1; index-- )
{
   printf("condition is true at index %g\n", index );
}
SEE ALSO

References:

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

More information:

See updated/extended version on-line.