Skip to content

Heikin-Ashi — 파생 시리즈의 증명

같은 x 위에 원본 캔들(위)과 heikinAshi(derive)로 평활한 캔들(아래) — 새 시리즈 타입이 아니라 candleSeries() + derive 조합이다. 아래 봉이 위보다 몸통이 매끈하고 꼬리가 짧은 것이 증명이다.

소스

apps/examples/src/cases/heikin-ashi.ts — CI가 타입체크하는 실물이다.

ts
import { PlotBuilder, browserDeps } from "@finchart/dom";
import type { OHLC } from "@finchart/core";
import { candleSeries, priceFormat, timeTicks } from "@finchart/core";
import { heikinAshi } from "@finchart/indicators";
import { fixtureCandles } from "./fixture";
import { chartHost } from "./stage";

export const title = "Heikin-Ashi — 파생 시리즈의 증명";
export const description =
  "같은 x 위에 원본 캔들(위)과 heikinAshi(derive)로 평활한 캔들(아래) — 새 시리즈 타입이 아니라 candleSeries() + derive 조합이다. 아래 봉이 위보다 몸통이 매끈하고 꼬리가 짧은 것이 증명이다.";

export function mount(container: HTMLElement): () => void {
  const host = chartHost(container, 640);
  const plot = PlotBuilder.create<OHLC>(browserDeps({ autoSize: true }))
    .setSize(container.clientWidth || 900, 640)
    .setAxis({
      x: { ticks: timeTicks({ timeZone: "UTC", locale: "ko" }) },
      y: { position: "right", format: priceFormat({ compact: true, locale: "ko" }) },
    })
    .build(host);

  const candles = fixtureCandles();

  plot.mainPane.addSeries({ series: candleSeries(), data: candles, name: "원본" });

  // derive는 등록의 data 전체를 받는다 — heikinAshi는 원본 OHLC를 그대로
  // 받아 상태형으로 훑고 같은 길이의 OHLC를 낸다 (docs/plot-contract.md
  // "파생 시리즈").
  plot.addPane({ flex: 1, minHeight: 200 }).addSeries({
    series: candleSeries(),
    data: candles,
    derive: heikinAshi,
    name: "Heikin-Ashi",
  });

  return Object.assign(
    () => {
      plot.destroy();
      host.remove();
    },
    { requestRender: () => plot.requestRender() },
  );
}