Indicators
Oscillators
RSI, MACD, Stochastic, CCI, Williams %R, ROC, Momentum, ATR and more.
"use client";
import { ChartCanvas, Pane } from "@reincharts/core";
import { CandlestickSeries } from "@reincharts/series";
import { Indicator, indicators } from "@reincharts/indicators";
import { Grid, XAxis, YAxis } from "@reincharts/axes";
import { Crosshair } from "@reincharts/coordinates";
import { Legend } from "@reincharts/tooltip";
import { useState } from "react";
import { Segmented, WithToolbar } from "@/components/preview/controls";
import { daily } from "@/lib/data";
import { useDocsChartTheme } from "@/lib/use-docs-theme";
const ids = ["rsi", "macd", "stochastic", "cci", "williamsR", "roc", "momentum", "atr"] as const;
export default function Oscillators() {
const theme = useDocsChartTheme();
const [id, setId] = useState<(typeof ids)[number]>("rsi");
return (
<WithToolbar toolbar={<Segmented label="indicator" value={id} options={ids} onChange={setId} />}>
<ChartCanvas data={daily} theme={theme} barSpacing={8}>
<Pane size={2}>
<Grid />
<CandlestickSeries name="MSFT" />
<YAxis />
<Legend title="MSFT · 1D" />
</Pane>
<Pane>
<Grid vertical={false} />
<Indicator key={id} definition={indicators[id]} />
<YAxis />
<Legend />
</Pane>
<XAxis />
<Crosshair />
</ChartCanvas>
</WithToolbar>
);
}Usage
Oscillators need their own pane:
<Pane size={3}>{/* price */}</Pane>
<Pane>
<RSI period={14} />
<YAxis />
<Legend />
</Pane>| Id | Indicator | Component |
|---|---|---|
rsi | Relative Strength Index (30 / 50 / 70 levels) | <RSI> |
macd | MACD line, signal and 4-color histogram | <MACD> |
stochastic | %K / %D with 20 / 80 levels (fast, slow, full) | <Stochastic> |
cci | Commodity Channel Index | |
williamsR | Williams %R | |
mfi | Money Flow Index | |
roc | Rate of change (%) | |
momentum | Momentum | |
atr | Average True Range | <ATR> |
stddev | Standard deviation | |
elderImpulse | Elder impulse system |
The y range fits the data plus the levels. To keep RSI on 0-100, pass fitDomain or pin the pane's scale with
domain: [0, 100].