Indicators
이 콘텐츠는 아직 번역되지 않았습니다.
Bollinger Bands and EMA on the price pane, RSI (14) with a chained SMA (9) in an oscillator pane, and volume below.
const candles = chart.addSeries('candlestick');candles.setData({ time, open, high, low, close, volume });
const fast = candles.addIndicator('ema', { params: { period: 12 } });const bands = candles.addIndicator('bollinger', { params: { period: 20, multiplier: 2 }, outputs: { middle: { color: '#ffa726', lineStyle: 'dashed' } },});const strength = candles.addIndicator('rsi');// Chains: an indicator of another indicator's output.const smoothed = strength.output().addIndicator('sma', { params: { period: 9 } });
fast.applyOptions({ params: { period: 21 } }); // recomputed in the backgroundbands.output('upper').applyOptions({ color: '#42a5f5' }); // style onlystrength.output().lastValue(); // for a legend, NaN until computedsmoothed.remove();import type { OhlcColumns } from '@lumen-ticks/core';import { LumenChart, type ChartApi } from '@lumen-ticks/react';import { useEffect, useState } from 'react';
export function IndicatorsChart({ data }: { data: OhlcColumns }) { const [chart, setChart] = useState<ChartApi | null>(null);
useEffect(() => { if (chart === null) return; const candles = chart.addSeries('candlestick'); candles.setData(data);
const fast = candles.addIndicator('ema', { params: { period: 12 } }); const bands = candles.addIndicator('bollinger', { params: { period: 20, multiplier: 2 }, outputs: { middle: { color: '#ffa726', lineStyle: 'dashed' } }, }); const strength = candles.addIndicator('rsi'); // Chains: an indicator of another indicator's output. const smoothed = strength.output().addIndicator('sma', { params: { period: 9 } });
fast.applyOptions({ params: { period: 21 } }); // recomputed in the background bands.output('upper').applyOptions({ color: '#42a5f5' }); // style only strength.output().lastValue(); // for a legend, NaN until computed smoothed.remove();
return () => chart.removeSeries(candles); // removes indicators reading candles too }, [chart, data]);
return <LumenChart ref={setChart} style={{ height: 420 }} />;}<script setup lang="ts">import type { OhlcColumns } from '@lumen-ticks/core';import { LumenChart, type ChartApi } from '@lumen-ticks/vue';import { onMounted, useTemplateRef } from 'vue';
const props = defineProps<{ data: OhlcColumns }>();const chartEl = useTemplateRef<{ chart: ChartApi | null }>('chartEl');
onMounted(() => { const chart = chartEl.value?.chart; if (!chart) return; const candles = chart.addSeries('candlestick'); candles.setData(props.data);
const fast = candles.addIndicator('ema', { params: { period: 12 } }); const bands = candles.addIndicator('bollinger', { params: { period: 20, multiplier: 2 }, outputs: { middle: { color: '#ffa726', lineStyle: 'dashed' } }, }); const strength = candles.addIndicator('rsi'); const smoothed = strength.output().addIndicator('sma', { params: { period: 9 } });
fast.applyOptions({ params: { period: 21 } }); bands.output('upper').applyOptions({ color: '#42a5f5' }); strength.output().lastValue(); smoothed.remove();});</script>
<template> <LumenChart ref="chartEl" style="height: 420px" /></template><script lang="ts"> import type { OhlcColumns } from '@lumen-ticks/core'; import { lumenChart, type ChartApi } from '@lumen-ticks/svelte';
let { data }: { data: OhlcColumns } = $props();
function onReady(chart: ChartApi) { const candles = chart.addSeries('candlestick'); candles.setData(data);
const fast = candles.addIndicator('ema', { params: { period: 12 } }); const bands = candles.addIndicator('bollinger', { params: { period: 20, multiplier: 2 }, outputs: { middle: { color: '#ffa726', lineStyle: 'dashed' } }, }); const strength = candles.addIndicator('rsi'); const smoothed = strength.output().addIndicator('sma', { params: { period: 9 } });
fast.applyOptions({ params: { period: 21 } }); bands.output('upper').applyOptions({ color: '#42a5f5' }); strength.output().lastValue(); smoothed.remove(); }</script>
<div style="height: 420px" use:lumenChart={{ onReady }}></div>import type { OhlcColumns } from '@lumen-ticks/core';import { LumenChart, type ChartApi } from '@lumen-ticks/solid';
export function IndicatorsChart(props: { data: OhlcColumns }) { const handleReady = (chart: ChartApi) => { const candles = chart.addSeries('candlestick'); candles.setData(props.data);
const fast = candles.addIndicator('ema', { params: { period: 12 } }); const bands = candles.addIndicator('bollinger', { params: { period: 20, multiplier: 2 }, outputs: { middle: { color: '#ffa726', lineStyle: 'dashed' } }, }); const strength = candles.addIndicator('rsi'); const smoothed = strength.output().addIndicator('sma', { params: { period: 9 } });
fast.applyOptions({ params: { period: 21 } }); bands.output('upper').applyOptions({ color: '#42a5f5' }); strength.output().lastValue(); smoothed.remove(); };
return <LumenChart class="chart-box" onReady={handleReady} />;}Indicators run in the data engine: computed in the background after a load, a parameter change or
a prepend (after a prepend only as far as the new history changes them), and incrementally on every
tick, whose message carries the bar and the latest value of every indicator together. Their outputs are series on the main timeline, with levels of
detail like any other, drawn on the price pane as lines (MACD’s histogram as a histogram) and
included in autoscale. While an indicator is being recomputed its old values stay on screen;
chart.whenIdle() resolves once the new ones are drawn.
Built-in: sma, ema, wma, rsi, macd (outputs macd, signal, histogram), bollinger
(upper, middle, lower), atr, stochastic (k, d), vwap (restarting every UTC day by
default; anchor in milliseconds, 0 for never), highest and lowest. An input reads a column of
the source by default (close, or high, low, close for ATR and Stochastic); pass
inputs: ['high'], inputs: [{ series: other, column: 'close' }] or inputs: [someIndicator.output()]
to read something else. Missing bars and the warm-up read as gaps (NaN). Values are deterministic:
incremental updates give the same bits as a full computation. An input can also read trades or a
book per bar, inputs: [{ series: trades, column: 'count' }]: see
indicators over marks.
A histogram series is also available for your own data, for example volume:
chart.addSeries('histogram', { color: '#26a69a', negativeColor: '#ef5350', base: 0 }).
Independent indicator panes
Section titled “Independent indicator panes”Set a positive paneWeight on a named price scale to give its series a pane below the price chart.
The main pane has weight 1 by default. Named panes follow the order of the priceScales options.
This layout assigns half the height to price and a quarter each to RSI and volume.
chart.applyOptions({ priceScales: { oscillator: { paneWeight: 0.5, visible: true }, volume: { paneWeight: 0.5, visible: true }, }, crosshair: { mode: 'nearest' },});candles.addIndicator('rsi', { priceScaleId: 'oscillator' });const volume = chart.addSeries('histogram', { priceScaleId: 'volume' });import type { LineColumns, OhlcColumns } from '@lumen-ticks/core';import { LumenChart, type ChartApi, type ChartOptions, type DeepPartial } from '@lumen-ticks/react';import { useEffect, useMemo, useState } from 'react';
export function MultiPaneChart({ bars, volumeData, oscillatorWeight = 0.5,}: { bars: OhlcColumns; volumeData: LineColumns; oscillatorWeight?: number;}) { const [chart, setChart] = useState<ChartApi | null>(null); const options = useMemo<DeepPartial<ChartOptions>>( () => ({ priceScales: { oscillator: { paneWeight: oscillatorWeight, visible: true }, volume: { paneWeight: 0.5, visible: true }, }, crosshair: { mode: 'nearest' }, }), [oscillatorWeight], );
useEffect(() => { if (chart === null) return; const candles = chart.addSeries('candlestick'); candles.setData(bars); candles.addIndicator('rsi', { priceScaleId: 'oscillator' }); const volume = chart.addSeries('histogram', { priceScaleId: 'volume' }); volume.setData(volumeData); return () => { chart.removeSeries(volume); chart.removeSeries(candles); }; }, [chart, bars, volumeData]);
return <LumenChart ref={setChart} options={options} style={{ height: 480 }} />;}<script setup lang="ts">import type { LineColumns, OhlcColumns } from '@lumen-ticks/core';import { LumenChart, type ChartApi, type ChartOptions, type DeepPartial } from '@lumen-ticks/vue';import { computed, onMounted, useTemplateRef } from 'vue';
const props = withDefaults( defineProps<{ bars: OhlcColumns; volumeData: LineColumns; oscillatorWeight?: number }>(), { oscillatorWeight: 0.5 },);const chartEl = useTemplateRef<{ chart: ChartApi | null }>('chartEl');const options = computed<DeepPartial<ChartOptions>>(() => ({ priceScales: { oscillator: { paneWeight: props.oscillatorWeight, visible: true }, volume: { paneWeight: 0.5, visible: true }, }, crosshair: { mode: 'nearest' },}));
onMounted(() => { const chart = chartEl.value?.chart; if (!chart) return; const candles = chart.addSeries('candlestick'); candles.setData(props.bars); candles.addIndicator('rsi', { priceScaleId: 'oscillator' }); const volume = chart.addSeries('histogram', { priceScaleId: 'volume' }); volume.setData(props.volumeData);});</script>
<template> <LumenChart ref="chartEl" :options="options" style="height: 480px" /></template><script lang="ts"> import type { LineColumns, OhlcColumns } from '@lumen-ticks/core'; import { lumenChart, type ChartApi, type ChartOptions, type DeepPartial } from '@lumen-ticks/svelte';
let { bars, volumeData, oscillatorWeight = 0.5, }: { bars: OhlcColumns; volumeData: LineColumns; oscillatorWeight?: number } = $props();
const options = $derived<DeepPartial<ChartOptions>>({ priceScales: { oscillator: { paneWeight: oscillatorWeight, visible: true }, volume: { paneWeight: 0.5, visible: true }, }, crosshair: { mode: 'nearest' }, });
function onReady(chart: ChartApi) { const candles = chart.addSeries('candlestick'); candles.setData(bars); candles.addIndicator('rsi', { priceScaleId: 'oscillator' }); const volume = chart.addSeries('histogram', { priceScaleId: 'volume' }); volume.setData(volumeData); }</script>
<div style="height: 480px" use:lumenChart={{ options, onReady }}></div>import type { LineColumns, OhlcColumns } from '@lumen-ticks/core';import { LumenChart, type ChartApi } from '@lumen-ticks/solid';
export function MultiPaneChart(props: { bars: OhlcColumns; volumeData: LineColumns; oscillatorWeight?: number;}) { const handleReady = (chart: ChartApi) => { const candles = chart.addSeries('candlestick'); candles.setData(props.bars); candles.addIndicator('rsi', { priceScaleId: 'oscillator' }); const volume = chart.addSeries('histogram', { priceScaleId: 'volume' }); volume.setData(props.volumeData); };
return ( <LumenChart class="chart-box" options={{ priceScales: { oscillator: { paneWeight: props.oscillatorWeight ?? 0.5, visible: true }, volume: { paneWeight: 0.5, visible: true }, }, crosshair: { mode: 'nearest' }, }} onReady={handleReady} /> );}Each pane fits its own price range. Pan, zoom and the vertical crosshair share the time axis.
Dragging a visible price axis scales that pane. Adjust its height at runtime with
chart.priceScale('oscillator').applyOptions({ paneWeight: 0.75 }). A weight of zero
returns the series to the main pane as an overlay. Saving and restoring the chart options
and series preserves the pane sizes and assignments.