> For the complete documentation index, see [llms.txt](https://fto-2.gitbook.io/fto-indicators-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fto-2.gitbook.io/fto-indicators-docs/access-to-bar-arrays/ibarshift.md).

# iBarShift

Returns the bar index for a specified time in the symbol's price history.

## Syntax

```typescript
iBarShift(symbol: string, timeframe: number, time: FTODate, exact: boolean): number
```

## Parameters

* `symbol`: The symbol to get data for
* `timeframe`: The timeframe of the data (in minutes)
* `time`: [FTODate](/fto-indicators-docs/fto-date.md) The time to search for
* `exact`: Whether to require an exact match

## Return Value

Returns a `number` representing the index of the bar corresponding to the specified time. Returns -1 if no matching bar is found.

## Description

The `iBarShift` method searches for a bar with a specific opening time and returns its index. If `exact` is true, only bars with exactly matching times will be considered. If `exact` is false, the method will return the index of the nearest bar that opened before the specified time.

## Example

```typescript
// Find bar index for a specific time
const searchTime = this.api.createFTODate("2023-01-01T10:00:00Z");
const barIndex = this.api.iBarShift("EURUSD", 60, searchTime, true);

// Check if specific time exists in history
if (this.api.iBarShift("EURUSD", 60, searchTime, true) !== -1) {
  console.log("Bar found for the specified time");
}

// Find nearest bar before a time
const approxIndex = this.api.iBarShift("EURUSD", 60, searchTime, false);

// Get price at specific historical time
const historicalTime = this.api.createFTODate("2023-06-01T14:30:00Z");
const index = this.api.iBarShift("EURUSD", 60, historicalTime, false);
if (index !== -1) {
  const price = this.api.iClose("EURUSD", 60, index);
  console.log(`Price at ${historicalTime}: ${price}`);
}

// Find bar index for current time
const now = this.api.createFTODate(Date.now());
const currentIndex = this.api.iBarShift("EURUSD", 60, now, false);
```
