I am trying to create a Heikin Ashi chart using amCharts 5, but I’m not sure how to set it up correctly. I couldn’t find direct examples in the documentation.
Here’s what I’ve done so far:
- I’m able to display a basic candlestick chart using XYChart and CandlestickSeries.
- I understand that Heikin Ashi uses modified values for open, close, high, and low.
How can I modify my data or the series configuration to calculate and display Heikin Ashi candles? Should I preprocess the data or can it be done dynamically using amCharts 5 features?
Here’s a simplified version of my current code:
// Create chart
let chart = am5.Root.new("chartdiv").container.children.push(am5xy.XYChart.new(am5.Root.new(), {}));
// Add data (example format)
let data = [
{ date: "2023-01-01", open: 100, high: 110, low: 95, close: 105 },
{ date: "2023-01-02", open: 105, high: 115, low: 100, close: 110 },
// more data...
];
// Create series
let series = chart.series.push(
am5xy.CandlestickSeries.new(am5.Root.new(), {
xAxis: chart.xAxes.push(am5xy.DateAxis.new(am5.Root.new(), { baseInterval: { timeUnit: "day", count: 1 } })),
yAxis: chart.yAxes.push(am5xy.ValueAxis.new(am5.Root.new(), {})),
openValueYField: "open",
valueYField: "close",
highValueYField: "high",
lowValueYField: "low",
categoryXField: "date",
})
);
series.data.setAll(data);
Do I need to calculate the Heikin Ashi values (HA_open, HA_close, HA_high, HA_low) manually before passing the data to the chart? Or is there a built-in feature in amCharts 5 to handle this transformation?
Any example or guidance would be greatly appreciated!