Skip to content

The bar (candle) your algorithm is in: in onTick the bar still forming, in onIntervalClose the bar that just closed.

declare const PRICE: PriceBar;
interface PriceBar extends OHLC {
/** The bar's open time. */
readonly TIME: Date;
readonly MID: OHLC;
readonly BID: OHLC;
readonly ASK: OHLC;
}
interface OHLC {
readonly OPEN: number;
readonly HIGH: number;
readonly LOW: number;
readonly CLOSE: number;
}

PRICE.OPEN to PRICE.CLOSE are mid prices, the same as OPEN to CLOSE. PRICE.BID and PRICE.ASK give each side. PRICE.TIME is the bar’s open time. Each timeframe has its own PRICE.

function onIntervalClose() {
const range = PRICE.HIGH - PRICE.LOW;
const spreadAtClose = PRICE.ASK.CLOSE - PRICE.BID.CLOSE;
log("Bar from", PRICE.TIME.toISOString(), "range", range, "spread", spreadAtClose);
}