Technical indicators in Angular Stock chart component

27 Apr 20245 minutes to read

A technical indicator is a mathematical calculation based on historic price, volume or open interest information that aims to forecast financial market direction.

StockChart supports 10 types of technical indicators namely Accumulation Distribution, ATR, EMA,SMA,TMA,Momentum,MACD,RSI,Stochastic,Bollinger Band. By using indicator dropdown box you can add an remove the required indicators types.

Accumulation Distribution

Accumulation Distribution combines price and volume to show how money may be flowing into or out of stock.
To render a Accumulation Distribution Indicator, use indicator type as AccumulationDistribution and inject AccumulationDistributionIndicatorService into the @NgModule.providers.
To calculate the signal line volume field is additionally added with dataSource.

Average True Range (ATR)

ATR measures the stock volatility by comparing the current value with the previous value. To render a Average True Range (ATR) Indicator, use indicator type as Atr and inject AtrIndicatorService into the @NgModule.providers.

Bollinger Band

A StockChart overlay that shows the upper and lower limits of normal price movements based on the standard deviation of prices.
To render a Bollinger Band, use indicator type as BollingerBand and inject BollingerBandsService into the @NgModule.providers.
Bollinger band will be represented by three lines (upperLine, lowerLine, signalLine).Bollinger Band default values of the period is 14 and standardDeviations is 2.

Exponential Moving Average (EMA)

Moving average Indicators are used to define the direction of the trend. To render a EMA Indicator, use indicator type as Ema and inject EMAIndicatorService into the @NgModule.providers.

Momentum

Momentum shows the speed at which the price of the stock is changing. To render a Momentum indicator, use indicator type as Momentumand inject MomentumIndicatorService into the @NgModule.providers. Momentum indicator will be represented by two lines (upperLine, signalLine).In momentum indicator the upperBand value is always render at the value 100.

Moving Average Convergence Divergence (MACD)

MACD is based on the difference between two EMA’s. To render a MACD Indicator, use indicator type as MACD and inject MACDIndicatorService into the @NgModule.providers.MACD indicator will be represented by MACD line,signal line, MACD histogram. MACD histogram is used to differentiate MACD line and signal line.

Relative Strength Index (RSI)

RSI shows how strongly a stock is moving in its current direction. To render a RSI Indicator, use indicator type asRsi and inject RsiIndicatorService into the @NgModule.providers.RSI indicator will be represented by three lines (upperBand, lowerBand, signalLine). The upperBand and lowerBand values are customized by overBought and overSold properties of indicator and the signalLine is calculated by RSI formula.

Simple Moving Average (SMA)

Moving average Indicators are used to define the direction of the trend. To render a SMA Indicator, use indicator type as Sma and inject SmaIndicatorService module using @NgModule.providers.

Stochastic

It shows how a stock is, when compared to previous state. To render a Stochastic indicator, use indicator type as Stochastic and inject StochasticIndicatorService module using @NgModule.providers method.
stochastic indicator will be represented by four lines (upperLine, lowerLine, periodLine, signalLine).
In stochastic indicator the upperBand value and lowerBand value is customized by overBought and overSold properties of indicators and the periodLine and signalLine is render based on stochastic formula.

Triangular Moving Average (TMA)

Moving average indicators are used to define the direction of the trend. To render a TMA Indicator, use indicator type as TMA and inject TmaIndicatorService module using @NgModule.providers.

import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule, StockChartAllModule } from '@syncfusion/ej2-angular-charts'
import { CandleSeriesService, LineSeriesService, TmaIndicatorService, DateTimeService} from '@syncfusion/ej2-angular-charts'



import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { chartData } from './datasource';

@Component({
imports: [
         ChartModule, StockChartAllModule
    ],

providers: [ CandleSeriesService, LineSeriesService, TmaIndicatorService, DateTimeService],
standalone: true,
    selector: 'app-container',
    template:
            `<ejs-stockchart id='chartcontainer' style="display:block;" [title]='title' [primaryXAxis]='primaryXAxis' [primaryYAxis]='primaryYAxis'
              [chartArea]= 'chartArea'>
            <e-stockchart-indicators>
                <e-stockchart-indicator type='Tma' [dataSource]='data' xName='x' field="Close" high='high' low='low' open='open' fill="blue"
                close='close' volume='volume'> </e-stockchart-indicator>
            </e-stockchart-indicators>
        </ejs-stockchart>`
})
export class AppComponent implements OnInit {
 public data: Object[] = chartData;
    public primaryXAxis: Object = {
        title: 'Months',
        valueType: 'DateTime',
        intervalType: 'Months',
        majorGridLines: { width: 0}
    };
    public primaryYAxis: Object = {
        title: 'Price',
        labelFormat: '${value}',
        minimum: 30, maximum: 180,
        interval: 30,
    };
    public title: string = 'AAPL 2012-2017';
    public chartArea : Object = {
      border: { width : 0}
    };
    constructor() {
        //code
    } ngOnInit(): void {
        throw new Error('Method not implemented.');
    }
;
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Module Dependencies
To render a Indicator, it is mandatory to inject LineSeriesService module..
In addition to that, MACD Indicator requires ColumnSeriesService and BollingerBands requires RangeAreaSeriesService.