iBarShift
Syntax
iBarShift(symbol: string, timeframe: number, time: FTODate, exact: boolean): numberParameters
Return Value
Description
Example
Last updated
iBarShift(symbol: string, timeframe: number, time: FTODate, exact: boolean): numberLast updated
// 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);