iClose
Returns the close price of a bar in the specified symbol's price history.
Syntax
iClose(Symbol: string, TimeFrame: number, index: number): number
Parameters
Symbol
: The symbol to get data forTimeFrame
: 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 a number
representing the close price of the specified bar.
Description
The iClose
method retrieves the closing price 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.
Example
// 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;
Last updated