# 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);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fto-2.gitbook.io/fto-indicators-docs/access-to-bar-arrays/ibarshift.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
