Version: 1.0.0
Custom indicator
The CustomIndicator module lets developers register fully custom technical indicators with their own calculation logic and canvas rendering.
Overview
Custom indicators are registered via window.ChartingAPI.registerIndicator(id, config). They automatically appear in the chart's indicator selection popup once registered.
Indicator Types
overlay: Renders directly on the main chart price area (e.g. moving averages, Bollinger Bands).pane: Creates a dedicated sub-panel below the main chart (e.g. RSI, MACD, Momentum).
Registration API
window.ChartingAPI.registerIndicator('my_indicator', {
name: 'My Indicator',
type: 'overlay', // or 'pane'
params: { period: 14 },
defaultColor: '#ff0000',
levels: [30, 70], // Only for 'pane' type
calculate: function(bars, params) {
// Return array of calculated values (same length as bars)
return bars.map(b => b.close); // Example: identity
},
render: function(ctx, chart, values, bounds, color) {
// Draw the indicator line using ctx
}
});
name: 'My Indicator',
type: 'overlay', // or 'pane'
params: { period: 14 },
defaultColor: '#ff0000',
levels: [30, 70], // Only for 'pane' type
calculate: function(bars, params) {
// Return array of calculated values (same length as bars)
return bars.map(b => b.close); // Example: identity
},
render: function(ctx, chart, values, bounds, color) {
// Draw the indicator line using ctx
}
});
Built-in Examples
- custom_sma: Overlay Simple Moving Average with configurable
period. Renders a smooth purple line. - custom_momentum: Pane-based percentage momentum oscillator with shaded bands at ±10 levels.