Custom Indicators
The Angular financial chart component allows you to define custom financial indicators to display in the Indicator Pane.
Demo
In the Angular financial chart component, you can enable custom financial indicators by adding names for them to the customIndicatorNames property and performing calculations for them in the applyCustomIndicators event.
The following code example shows how to set up and calculate two custom indicators, one featuring the Simple Moving Average (SMA) and one displaying random values.
<igx-financial-chart
width="850px"
height="600px"
[dataSource]="data"
(applyCustomIndicators)="applyCustomIndicators($event)"
customIndicatorNames="Open, Open (SMA)">
</igx-financial-chart>
public applyCustomIndicators(event: { sender: any, args: FinancialChartCustomIndicatorArgs }) {
if (event.args.index === 0) {
const info: FinancialEventArgs = event.args.indicatorInfo;
const ds = info.dataSource;
const open = ds.openColumn;
for (let i = 0; i < ds.indicatorColumn.length; i++) {
ds.indicatorColumn[i] = open[i];
}
} else {
const info: FinancialEventArgs = event.args.indicatorInfo;
const ds = info.dataSource;
const close = ds.closeColumn;
for (let i = 0; i < ds.indicatorColumn.length; i++) {
let startIndex = i - 9;
if (startIndex < 0) {
startIndex = 0;
}
const count = (i - startIndex) + 1;
let sum = 0;
for (let j = startIndex; j <= i; j++) {
sum += close[j];
}
ds.indicatorColumn[i] = sum / count;
}
}
}