Search code examples
highchartsangular-highcharts

How to get a map of all series "type" names to parameters for HighCharts technical indicator series?


In highcharts stock charts, different series types have different parameters for example the paramaters for macd can be seen here: https://api.highcharts.com/highstock/series.macd.params

I would like to be able to get a map of type names, like "macd" or "sm", to parameters. Preferably an example using the typescript version of Highstock, or even better if it was in angular-highcharts. For example:

{
  "sm" => ["index" : 1 , "period": 2],
  "macd" => ["index": 11, "longperiod":12 , "period":23, "shortperiod":22],
  .
  .
  .
}

Edit:

To clarify, how would I create an object with the default params across all indicators as shown for MACD here on line 97: https://github.com/highcharts/highcharts/blob/9b3c23b50892f96487593fd7e553d9432e60f635/ts/Stock/Indicators/MACD/MACDIndicator.ts#L97

I would like to get the params before adding the series to the chart if possible.


Solution

  • The params for each type are available through the Highcharts.Series.types variable:

    import * as Highcharts from "highcharts/highstock";
    import HC_exporting from 'highcharts/modules/exporting';
    HC_exporting(Highcharts);
    import {Dictionary, PlotMacdOptions, Series, SeriesOptions} from 
       "highcharts";
    import IndicatorsAll from "highcharts/indicators/indicators-all";
    IndicatorsAll(Highcharts);
    
    const seriesType = "macd";
    const types: any= Highcharts.Series.types;
    console.log( types[seriesType].defaultOptions.params);
    

    enter image description here