Skip to content

One past price: by default the mid close n bars ago on your session’s instrument and timeframe.

declare const price: PriceFunction;
interface PriceFunction extends PriceSide {
readonly mid: PriceSide;
readonly bid: PriceSide;
readonly ask: PriceSide;
}
interface PriceSide {
/** The close `n` bars ago (0, the default, is the latest close), or the close of the bar at a time (`null` if there is none). */
(n?: number): number;
(at: Date): number | null;
open(n?: number): number;
open(at: Date): number | null;
high(n?: number): number;
high(at: Date): number | null;
low(n?: number): number;
low(at: Date): number | null;
close(n?: number): number;
close(at: Date): number | null;
ohlc(n?: number): Bar;
ohlc(at: Date): Bar | null;
}
interface Bar extends OHLC {
/** The bar's open time. */
readonly TIME: Date;
}
  • n: how many bars ago; 0, the default, is the latest close. A negative number counts the same way: price(-5) is price(5). It must be a whole number.
  • at (instead of n): a Date. You get the bar that contains that time, or null if there was none.
Call Gives
price(n), price.close(n), price.mid(n) Mid close
price.open(n), price.high(n), price.low(n) Mid open, high, low
price.bid(n), price.ask(n) Bid or ask close
price.bid.high(n), price.ask.low(n) and so on That side’s open, high, low or close
price.ohlc(n), price.bid.ohlc(n) A bar with TIME, OPEN, HIGH, LOW, CLOSE

Every timeframe has the same price, such as H4.price.high(1).

The run stops with an error for a number that is not whole (“Value passed to price() must be an integer”), a value that is neither a number nor a date, or a date in the future. Asking for more history than was loaded makes the run wait while more loads, with a warning in the log; in a live session that pause delays your trading.

function onIntervalClose() {
const change = price(0) - price(10);
const yesterday = D1.price.ohlc(1);
log("Ten-bar change", change, "yesterday's range", yesterday.HIGH - yesterday.LOW);
}