iTime
Syntax
iTime(Symbol: string, TimeFrame: number, index: number): FTODateParameters
Return Value
Description
Example
Last updated
iTime(Symbol: string, TimeFrame: number, index: number): FTODateLast updated
// 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));
}