Lookup
- search the array for bar with specified date/time

Date/Time
(AmiBroker 5.40)


SYNTAX Lookup( array, datetime, mode = 0 )
RETURNS NUMBER
FUNCTION The function searches for the bar with specified datetime and returns the value from the same position of the input array.

Parameter 'mode' decides how search is performed in case when exact match is not found:

  • mode = 0 - find exact match, otherwise return Null
  • mode = -1 - find exact match, otherwise return nearest predecesor (if datetime is past last bar it will return last bar value)
  • mode = -2 - find exact match, otherwise return nearest predecessor EXCEPT the very last bar (if searched datetime is past last bar it will return Null)
  • mode = 1 - find exact match, otherwise return nearest successor (if datetime is before first bar it will return first bar value)
  • mode = 2 - find exact match, otherwise return nearest successor EXCEPT the very first bar (if searched datetime is before first bar it will return Null)

This function uses very fast binary search and it is many times faster than previous AFL-based methods such as FindValueAtDateTime() presented in the past. Any call to FindValueAtDateTime ( input, dt, value ) can be now replaced with Lookup( input, value ) (here is no need to pass dt- datetime).

NOTE: This function does not affect QuickAFL required bars, therefore it will only search bars that are actually loaded in arrays. For indicators it may mean that it won't be able to find value if it is invisible, unless you use SetBarsRequired() function to ensure that more bars are loaded.

EXAMPLE InputDate = "2011-04-05";
Title = "Close value at (or before) " + InputDate + " is " + Lookup( Close, _DT( InputDate ), -1 );
SEE ALSO DateTime() function , StrToDateTime() function , _DT() function

References:

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

More information:

See updated/extended version on-line.