Skip to content

charton API


charton API / @chart-on/core / index / PriceBarBuilder

Class: PriceBarBuilder ​

Defined in: packages/core/src/price-bars.ts:137

Turns time bars into price-based bars and keeps them current as live bars arrive. Load history with setData, then send each new or changed source bar to update, and apply what it returns to a candle series:

ts
const builder = new PriceBarBuilder({ type: 'renko', size: { kind: 'fixed', size: 5 } });
candles.setData(builder.setData(bars));
const change = builder.update(bar);
if (change.reset) candles.setData(builder.bars, { keepVisibleRange: true });
else for (const b of change.bars) candles.update(b);

Constructors ​

Constructor ​

new PriceBarBuilder(options): PriceBarBuilder

Defined in: packages/core/src/price-bars.ts:148

Parameters ​

options ​

PriceBarOptions

Returns ​

PriceBarBuilder

Properties ​

options ​

readonly options: Readonly<PriceBarOptions>

Defined in: packages/core/src/price-bars.ts:138

Accessors ​

bars ​

Get Signature ​

get bars(): PriceBar[]

Defined in: packages/core/src/price-bars.ts:166

Every price bar, oldest first (copies).

Returns ​

PriceBar[]


size ​

Get Signature ​

get size(): number

Defined in: packages/core/src/price-bars.ts:161

The box size in effect: a price step, resolved from options.size when data is loaded. NaN before that. An ATR or percent size that comes out zero (flat or zero prices) is worked out again from each new source bar, and no price bars form until it is positive.

Returns ​

number

Methods ​

barAt() ​

barAt(time): PriceBar | undefined

Defined in: packages/core/src/price-bars.ts:225

The price bar whose slot time is (see PriceBar.time), or undefined.

Parameters ​

time ​

number

Returns ​

PriceBar | undefined


setData() ​

setData(source): PriceBar[]

Defined in: packages/core/src/price-bars.ts:174

Replace the source bars and rebuild. Invalid bars, and bars not newer than the one before, are skipped. Returns the price bars, as bars does.

Parameters ​

source ​

readonly Bar[]

Returns ​

PriceBar[]


update() ​

update(bar): PriceBarUpdate

Defined in: packages/core/src/price-bars.ts:196

Add a source bar newer than the last one, or replace the last one (same time) as it forms. Older and invalid bars are ignored.

Parameters ​

bar ​

Bar

Returns ​

PriceBarUpdate