Technical Indicators
ChartSpire provides a comprehensive suite of technical indicators for advanced market analysis. This guide will help you understand how to use and customize the indicator system.
Main vs. Sub Indicators
ChartSpire indicators are categorized into two types:
Main Indicators: These are overlaid directly on the price chart (candlesticks/bars) and share the same price scale. Examples include Moving Averages, Bollinger Bands, and Ichimoku Cloud.
Sub Indicators: These are displayed in separate panels below the main price chart, typically with their own scale. Examples include RSI, MACD, and Volume.
Available Indicators
ChartSpire offers 80+ indicators
Adding indicators via API
You can add indicators programmatically when creating the chart:
import { ChartSpire } from 'chartspire'
const chart = new ChartSpire({
container: document.getElementById('chart-container'),
// Other options...
indicators: ['RSI', 'MACD']
})Configuring Indicator Parameters
Each indicator in ChartSpire has configurable parameters that affect its calculation and display.
Via User Interface
To configure an existing indicator:
- Hover over the indicator in the chart or in a sub-panel
- Click on the settings icon (gear) in the indicator tooltip
- Adjust parameters in the configuration modal that appears
- Click "Apply" to update the indicator with new parameters
Common parameter types include:
- Periods/lengths (e.g., SMA length, RSI period)
- Source data (close, open, high, low, hl2, hlc3, ohlc4)
- Calculation methods
- Visual options (line styles, colors)
Custom Indicator Styling
Via User Interface
- To customize indicator styling:
- Access the indicator settings as described above
- Navigate to the "Style" tab in the configuration modal
- Adjust colors, line styles, thickness, and other visual properties
- Click "Apply" to update the indicator appearance
Creating Custom Indicators
ChartSpire allows for creating and registering custom indicators:
import { IndicatorDefinition } from "chartspire";
// Define a custom indicator
const testIndicator: IndicatorDefinition<any> = {
isMainIndicator: false,
isSubIndicator: true,
parameters: [],
name: 'testIndicator',
shortName: 'testIndicator',
figures: [{
key: 'close',
title: 'close: ',
type: 'line'
}],
calc: dataList => dataList.map(data => ({ close: data.close }))
}
export default testIndicatorOnce you have defined your custom indicator, you can register it using the createIndicator function:
import { createIndicator } from 'chartspire'
import testIndicator from './test-indicator'
// Register the custom indicator
createIndicator(testIndicator)This simple example creates a sub-indicator that displays the closing price as a line. You can create more complex indicators by:
- Using different calculation methods in the
calcfunction - Adding multiple figures with different visualization types
- Configuring parameters that can be adjusted by users
Indicator definition
The indicator properties are of type IndicatorDefinition:
(
indicator: IndicatorDefinition = {
isMainIndicator: boolean,
isSubIndicator: boolean,
name: string
parameters: IndicatorParameters
shortName?: string
precision?: number
calcParams?: unknown[]
shouldOhlc?: boolean
shouldFormatBigNumber?: boolean
visible?: boolean
zLevel?: number
extendData?: unknown
series?: 'normal' | 'price' | 'volume',
figures?: Array<{
key: string
title?: string
type?: string
baseValue?: number
attrs?: (params: object) => object
styles?: (params: object) => object
}>
minValue?: number
maxValue?: number
styles?: Partial<IndicatorStyle>
shouldUpdate?: (prev: Indicator, current: Indicator) => (boolean | { calc: boolean, draw: boolean })
calc: (candleStickData: CandleStickData[], indicator: Indicator) => Record<Timestamp, unknown> | Promise<Record<Timestamp, unknown>>
regenerateFigures?: (calcParams: unknown[]) => Array<{
key: string
title?: string
type?: string
baseValue?: number
attrs?: (params: object) => object
styles?: (params: object) => object
}>
createTooltipDataSource?: (params: object) => ({
name?: string
calcParamsText?: string
features?: Array<{
id?: string
position?: 'left' | 'middle' | 'right'
marginLeft?: number
marginTop?: number
marginRight?: number
marginBottom?: number
paddingLeft?: number
paddingTop?: number
paddingRight?: number
paddingBottom?: number
size?: number
color?: string
activeColor?: string
backgroundColor?: string
activeBackgroundColor?: string
type?: 'path' | 'icon_font'
path?: {
style?: 'stroke' | 'fill'
path?: string
lineWidth?: number
}
iconFont?: {
content?: string
family?: string
}
}>
legends?: Array<{
title: string |
{
text: string
color: string
}
value: string |
{
text: string
color: string
}
}>
})
draw?: (params: object) => boolean
onDataStateChange?: (params: object) => void
}
) => voidParameters
indicatorIndicator configuration.nameName, a unique identifier used for creation or modification.shortNameA short name, used for prompt display.precisionPrecision.calcParamsCalculate the parameters.shouldOhlcWhether to show theohlcbar.shouldFormatBigNumberWhether big numbers need to be formatted and displayed.visibleWhether it is visible.zLevelHierarchy only works between indicators.extendDataCustom the extended data.seriesSeries, supportsnormal,priceandvolume, whenpriceandprecisionis not set, the precision will follow the price precision, whenvolumeandprecisionis not set, the precision will follow the volume precision.figuresFigure configuration, an array of items containingobjectconfiguration.keyThe identifier of the data value, corresponding to thekeyof the data sub-item returned bycalc.typeThe type of figure that supports the type returned bycandleStickData.getSupportedFigures.baseValueThe basic control value, currently only works whentypeisrectandbar. When this value is valid, the graphics will be drawn up and down based on this value.attrsThe property value is a method, and the return value is the required property of the object obtained bycandleStickData.getFigureClass.stylesStyle is a method that returns the style required by the object obtained bycandleStickData.getFigureClass.
minValueSpecify a minimum value.maxValueSpecifies the maximum value.stylesStyle configuration, the type is the same asindicatorin the general styleStyles.shouldUpdateControl whether updates are needed.calcCalculation method.regenerateFiguresRegenerates the basic graphics configuration. This is triggered whencalcParamschanges. The return value type is the same asfigures.createTooltipDataSourceCreate custom prompts.drawCustom drawing method, if the return value istrue, it will override the default drawing.onDataStateChangeData change callback notification.