Exciting Update: Version 1.0.1 is now available, introducing high-performance technical indicators and custom drawing tools. Read more
Version: 1.0.0

Custom candle type

The CustomCandleType module allows developers to register entirely custom canvas-based candle renderers, replacing or extending the built-in drawing logic.

Overview

Custom renderers are registered via window.ChartingAPI.registerCandleType(id, fn). Once registered, the chart can use that renderer by setting chart.customDrawCandles = window.ChartingAPI.getCandleRenderer('your_id') and calling chart.render().

Renderer Function Signature

The renderer receives these arguments:

ParameterDescription
ctxHTML5 CanvasRenderingContext2D for drawing.
visibleBarsArray of bar objects: { time, open, high, low, close, volume }.
slotTotal pixel width allocated per candle (including gap).
bodyWCalculated candle body pixel width.
chartHTotal height in pixels of the price scale clip area.
priceToYHelper function (price) => y for coordinate conversion.
themeColorsActive theme colors: { bullColor, bearColor }.
xOffsetStarting X canvas position for the first visible bar.
chartInstanceThe chart widget context for additional API access.

Area Series Example

The built-in custom-candle-type.js ships with a premium area renderer as an example:

// Register a custom area renderer
window.ChartingAPI.registerCandleType('area', function(ctx, visibleBars, slot, bodyW, chartH, priceToY, T, xOffset, state) {
  // 1. Draw gradient fill below the line
  const gradient = ctx.createLinearGradient(0, 0, 0, chartH);
  gradient.addColorStop(0, 'rgba(38, 166, 154, 0.45)');
  gradient.addColorStop(1, 'rgba(38, 166, 154, 0.00)');
  // 2. Draw stroke line on top with vertex circles
  ctx.strokeStyle = '#26a69a';
  ctx.lineWidth = 2.5;
});

// Activate it on the chart
chart.customDrawCandles = window.ChartingAPI.getCandleRenderer('area');
chart.render();