prices()
A list of past prices, newest first: by default the mid closes of the last n bars of your session’s instrument and timeframe.
declare const prices: PricesFunction;
interface PricesFunction extends PricesSide { readonly mid: PricesSide; readonly bid: PricesSide; readonly ask: PricesSide;}
interface PricesSide { /** The last `n` closes, newest first, or the closes from a time, optionally to a time or for a duration in milliseconds. */ (n: number): number[]; (from: Date, to?: Date | number): number[]; open(n: number): number[]; open(from: Date, to?: Date | number): number[]; high(n: number): number[]; high(from: Date, to?: Date | number): number[]; low(n: number): number[]; low(from: Date, to?: Date | number): number[]; close(n: number): number[]; close(from: Date, to?: Date | number): number[]; ohlc(n: number): Bar[]; ohlc(from: Date, to?: Date | number): Bar[];}Parameters
Section titled “Parameters”- n: how many bars, 1 or more. The first item is the most recent close.
- from, to (instead of
n): every bar from aDate, up to now, up to anotherDate, or for a number of milliseconds.
The variants match price(): prices.high(n), prices.bid.close(n), prices.ask.ohlc(n) and so on, on every timeframe.
Errors
Section titled “Errors”The run stops for prices(0) (“Requested zero prices. Must be 1 or greater”), a number that is not whole, a range that ends before it starts, or a range in the future. As with price(), asking for more history than was loaded pauses the run while it loads.
Example
Section titled “Example”function onIntervalClose() { const closes = prices(20); const highs = H1.prices.high(24); log("20-bar average", Math.average(closes), "24-hour high", Math.highest(highs));}