iClose
Syntax
iClose(Symbol: string, TimeFrame: number, index: number): numberParameters
Return Value
Description
Example
Last updated
iClose(Symbol: string, TimeFrame: number, index: number): numberLast updated
// Get the close price of the current bar for EURUSD on H1 timeframe
const currentClose = this.api.iClose("EURUSD", 60, 0);
// Get the close price from 5 bars ago
const pastClose = this.api.iClose("EURUSD", 60, 5);
// Calculate the difference between current and previous bar's close prices
const closeDiff =
this.api.iClose("EURUSD", 60, 0) - this.api.iClose("EURUSD", 60, 1);
// Check if current bar closed higher than previous bar
if (this.api.iClose("EURUSD", 60, 0) > this.api.iClose("EURUSD", 60, 1)) {
console.log("Current bar closed higher");
}
// Calculate average closing price of last 3 bars
const avgClose =
(this.api.iClose("EURUSD", 60, 0) +
this.api.iClose("EURUSD", 60, 1) +
this.api.iClose("EURUSD", 60, 2)) /
3;