MQL4参考 时间序列和指标访问 iBarShift

iBarShift

Search for a bar by its time. The function returns the index of the bar which covers the specified time.

int  iBarShift(
   string           symbol,          // symbol
   int              timeframe,       // timeframe
   datetime         time,            // time
   bool             exact=false      // mode
   );

Parameters

symbol

[in]  Symbol name. NULL means the current symbol.

timeframe

[in]  Timeframe. It can be any of ENUM_TIMEFRAMES enumeration values. 0 means the current chart timeframe.

time

[in]  Time value for searching.

exact=false

[in]  Return mode when the bar is not found (false - iBarShift returns the nearest, true - iBarShift returns -1).

Returned value

Index of the bar which covers the specified time. If there is no bar for the specified time (history "gap"), the function will return -1 or the nearest bar index (depending on exact parameter).

Example:

  datetime some_time=D'2004.03.21 12:00';
  int      shift=iBarShift("EURUSD",PERIOD_M1,some_time);
  Print("index of the bar for the time ",TimeToStr(some_time)," is ",shift);