candlestick — 6.0.0

Render validated financial OHLC data with direction-aware bodies, wicks, colors, symbols, axes, and thresholds.

Signature

Signature
candlestick(spec: CandlestickSpec): string

Executable examples

OHLC candlestick

Source
candlestick({
  width: 30,
  height: 10,
  data: [[0, 100, 112, 96, 108], [1, 108, 114, 102, 105]],
  style: {
    rising: { symbol: '+', color: 'ansiGreen' },
    falling: { symbol: 'x', color: 'ansiRed' },
  },
  thresholds: [{ id: 'target', y: 110, color: 'ansiCyan' }],
});
Terminal output

   ▲                               
   │                             │ 
   ││                            │ 
   │━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
108┤+                            x 
105┤+                            x 
   │+                            │ 
   │+                            │ 
   │+                              
   ││                              
   ││                              
   └┬────────────────────────────┬▶
    0                            1 

CandlestickSpec

Complete candlestick chart specification.

type CandlestickSpec = Readonly<{
  /** Unique-X OHLC tuples satisfying `low <= open/close <= high`. */
  data: readonly CandlestickDatum[];
  /** Plot width in terminal columns. */
  width?: number;
  /** Plot height in terminal rows. */
  height?: number;
  /** Title rendered above the chart. */
  title?: string;
  /** Numeric X-axis configuration. */
  xAxis?: XAxis<number>;
  /** Numeric Y-axis configuration. */
  yAxis?: YAxis;
  /** Per-direction body colors and glyphs plus a wick glyph. */
  style?: CandlestickStyle;
  /** Named horizontal or vertical reference lines. */
  thresholds?: readonly ChartThreshold<number>[];
  /** Shared symbol overrides. `style` glyphs take precedence. */
  symbols?: Symbols;
  /** Logs out-of-bounds drawing attempts for diagnostics. */
  debugMode?: boolean;
}>;

data

readonly CandlestickDatum[]Required

Unique-X OHLC tuples satisfying low <= open/close <= high.

Related executable examples: OHLC candlestick

width

numberOptional

Plot width in terminal columns.

Related executable examples: OHLC candlestick

height

numberOptional

Plot height in terminal rows.

Related executable examples: OHLC candlestick

title

stringOptional

Title rendered above the chart.

Related executable examples: OHLC candlestick

xAxis

XAxis<number>Optional

Numeric X-axis configuration.

Related executable examples: OHLC candlestick

yAxis

YAxisOptional

Numeric Y-axis configuration.

Related executable examples: OHLC candlestick

style

CandlestickStyleOptional

Per-direction body colors and glyphs plus a wick glyph.

Related executable examples: OHLC candlestick

thresholds

readonly ChartThreshold<number>[]Optional

Named horizontal or vertical reference lines.

Related executable examples: OHLC candlestick

symbols

SymbolsOptional

Shared symbol overrides. style glyphs take precedence.

Related executable examples: OHLC candlestick

debugMode

booleanOptional

Logs out-of-bounds drawing attempts for diagnostics.

Related executable examples: OHLC candlestick

CandlestickStyle

Symbols and colors used to distinguish candle directions.

type CandlestickStyle = Readonly<{
  /** One-column wick glyph. */
  wick?: string;
  /** Style used when close is greater than open. */
  rising?: CandlestickMarkStyle;
  /** Style used when close is less than open. */
  falling?: CandlestickMarkStyle;
  /** Style used when close equals open. */
  unchanged?: CandlestickMarkStyle;
}>;

wick

stringOptional

One-column wick glyph.

Related executable examples: OHLC candlestick

rising

CandlestickMarkStyleOptional

Style used when close is greater than open.

Related executable examples: OHLC candlestick

falling

CandlestickMarkStyleOptional

Style used when close is less than open.

Related executable examples: OHLC candlestick

unchanged

CandlestickMarkStyleOptional

Style used when close equals open.

Related executable examples: OHLC candlestick

CandlestickMarkStyle

Body style for one candlestick price direction.

type CandlestickMarkStyle = Readonly<{
  /** One-column body glyph. */
  symbol?: string;
  /** ANSI color applied to the body and wick. */
  color?: Color;
}>;

symbol

stringOptional

One-column body glyph.

Related executable examples: OHLC candlestick

color

ColorOptional

ANSI color applied to the body and wick.

Related executable examples: OHLC candlestick

CandlestickSymbols

Shared candlestick glyph overrides.

type CandlestickSymbols = Readonly<{
  /** One-column wick glyph. */
  wick?: string;
  /** One-column glyph used when close is greater than open. */
  rising?: string;
  /** One-column glyph used when close is less than open. */
  falling?: string;
  /** One-column glyph used when close equals open. */
  unchanged?: string;
}>;

wick

stringOptional

One-column wick glyph.

Related executable examples: OHLC candlestick

rising

stringOptional

One-column glyph used when close is greater than open.

Related executable examples: OHLC candlestick

falling

stringOptional

One-column glyph used when close is less than open.

Related executable examples: OHLC candlestick

unchanged

stringOptional

One-column glyph used when close equals open.

Related executable examples: OHLC candlestick

XAxis

Structured X-axis configuration.

type XAxis = {
  /** Scale kind. Defaults to the kind inferred from X values. */
  scale?: XScale;
  /** Explicit category order or continuous scale extent. */
  domain?: XAxisDomain<X>;
  /** Exact native tick values or an exact tick count of at least two. */
  ticks?: number | readonly X[];
  /** Axis label rendered outside tick labels. */
  label?: string;
  /** Formatter called with native X values. */
  formatter?: AxisFormatter<X>;
  /** Hides the axis line, ticks, labels, and axis label. */
  hidden?: boolean;
  /** Hides tick markers and labels while retaining the axis line. */
  hideTicks?: boolean;
  /** Handling for labels that do not fit the available width. */
  labelCollision?: LabelCollisionPolicy;
  /** ANSI color applied to the axis line, ticks, tick labels, and label. */
  color?: Color;
};

scale

XScaleOptional

Scale kind. Defaults to the kind inferred from X values.

Related executable examples: OHLC candlestick

domain

XAxisDomain<X>Optional

Explicit category order or continuous scale extent.

Related executable examples: OHLC candlestick

ticks

number | readonly X[]Optional

Exact native tick values or an exact tick count of at least two.

Related executable examples: OHLC candlestick

label

stringOptional

Axis label rendered outside tick labels.

Related executable examples: OHLC candlestick

formatter

AxisFormatter<X>Optional

Formatter called with native X values.

Related executable examples: OHLC candlestick

hidden

booleanOptional

Hides the axis line, ticks, labels, and axis label.

Related executable examples: OHLC candlestick

hideTicks

booleanOptional

Hides tick markers and labels while retaining the axis line.

Related executable examples: OHLC candlestick

labelCollision

LabelCollisionPolicyOptional

Handling for labels that do not fit the available width.

Related executable examples: OHLC candlestick

color

ColorOptional

ANSI color applied to the axis line, ticks, tick labels, and label.

Related executable examples: OHLC candlestick

YAxis

Numeric Y-axis configuration.

type YAxis = {
  /** Explicit numeric extent as `[minimum, maximum]`. */
  domain?: readonly [number, number];
  /** Exact numeric tick values or an exact tick count of at least two. */
  ticks?: number | readonly number[];
  /** Axis label rendered outside tick labels. */
  label?: string;
  /** Formatter called for each numeric Y-axis tick. */
  formatter?: Formatter;
  /** Hides the axis line, ticks, labels, and axis label. */
  hidden?: boolean;
  /** Hides tick markers and labels while retaining the axis line. */
  hideTicks?: boolean;
  /** Reserves enough width for complete Y-axis tick labels. */
  showTickLabel?: boolean;
  /** ANSI color applied to the axis line, ticks, tick labels, and label. */
  color?: Color;
};

domain

readonly [number, number]Optional

Explicit numeric extent as [minimum, maximum].

Related executable examples: OHLC candlestick

ticks

number | readonly number[]Optional

Exact numeric tick values or an exact tick count of at least two.

Related executable examples: OHLC candlestick

label

stringOptional

Axis label rendered outside tick labels.

Related executable examples: OHLC candlestick

formatter

FormatterOptional

Formatter called for each numeric Y-axis tick.

Related executable examples: OHLC candlestick

hidden

booleanOptional

Hides the axis line, ticks, labels, and axis label.

Related executable examples: OHLC candlestick

hideTicks

booleanOptional

Hides tick markers and labels while retaining the axis line.

Related executable examples: OHLC candlestick

showTickLabel

booleanOptional

Reserves enough width for complete Y-axis tick labels.

Related executable examples: OHLC candlestick

color

ColorOptional

ANSI color applied to the axis line, ticks, tick labels, and label.

Related executable examples: OHLC candlestick