iVolume
Returns the tick volume of a bar in the specified symbol's price history.
Syntax
iVolume(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 tick volume of the specified bar.
Description
The iVolume
method retrieves the tick volume 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 volume represents the number of price changes (ticks) that occurred during the bar period.
Example
// Get the volume of the current bar for EURUSD on H1 timeframe
const currentVolume = this.api.iVolume("EURUSD", 60, 0);
// Get the volume from 5 bars ago
const pastVolume = this.api.iVolume("EURUSD", 60, 5);
// Calculate the total volume over the last 3 bars
const totalVolume =
this.api.iVolume("EURUSD", 60, 0) +
this.api.iVolume("EURUSD", 60, 1) +
this.api.iVolume("EURUSD", 60, 2);
// Calculate average volume over last 3 bars
const avgVolume = totalVolume / 3;
// Check if current volume is higher than previous bar
if (this.api.iVolume("EURUSD", 60, 0) > this.api.iVolume("EURUSD", 60, 1)) {
console.log("Volume is increasing");
}
// Check for volume spike (2x average)
const isVolumeSpiking = this.api.iVolume("EURUSD", 60, 0) > avgVolume * 2;
Last updated