iTime

Returns the opening time of a bar in the specified symbol's price history.

Syntax

iTime(Symbol: string, TimeFrame: number, index: number): FTODate

Parameters

  • Symbol: The symbol to get data for

  • TimeFrame: The timeframe of the data (in minutes)

  • index: The index of the bar (0 is current/last bar, 1 is previous bar, etc.)

Return Value

Returns an FTODate object representing the opening time of the specified bar.

Description

The iTime method retrieves the opening time of a bar at the specified index from the price history of a given symbol and timeframe. The index parameter uses zero-based indexing where 0 represents the current (most recent) bar. The returned time is in UTC timezone.

Example

// Get the time of the current bar for EURUSD on H1 timeframe
const currentTime = this.api.iTime("EURUSD", 60, 0);

// Get the time from 5 bars ago
const pastTime = this.api.iTime("EURUSD", 60, 5);

// Calculate time difference between bars
const timeDiff =
  this.api.iTime("EURUSD", 60, 0).toMilliseconds() -
  this.api.iTime("EURUSD", 60, 1).toMilliseconds();

// Check if bar is from today
const now = this.api.createFTODate(Date.now());
const barTime = this.api.iTime("EURUSD", 60, 0);
const isToday =
  barTime.getUTCDate() === now.getUTCDate() &&
  barTime.getUTCMonth() === now.getUTCMonth() &&
  barTime.getUTCFullYear() === now.getUTCFullYear();

// Get bar times for the last 3 bars
const barTimes = [];
for (let i = 0; i < 3; i++) {
  barTimes.push(this.api.iTime("EURUSD", 60, i));
}

Last updated