accumulation-distribution.src.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* *
  2. *
  3. * License: www.highcharts.com/license
  4. *
  5. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6. * */
  7. 'use strict';
  8. import H from '../parts/Globals.js';
  9. import '../parts/Utilities.js';
  10. var seriesType = H.seriesType;
  11. /* eslint-disable valid-jsdoc */
  12. // Utils:
  13. /**
  14. * @private
  15. */
  16. function populateAverage(xVal, yVal, yValVolume, i) {
  17. var high = yVal[i][1], low = yVal[i][2], close = yVal[i][3], volume = yValVolume[i], adY = close === high && close === low || high === low ?
  18. 0 :
  19. ((2 * close - low - high) / (high - low)) * volume, adX = xVal[i];
  20. return [adX, adY];
  21. }
  22. /* eslint-enable valid-jsdoc */
  23. /**
  24. * The AD series type.
  25. *
  26. * @private
  27. * @class
  28. * @name Highcharts.seriesTypes.ad
  29. *
  30. * @augments Highcharts.Series
  31. */
  32. seriesType('ad', 'sma',
  33. /**
  34. * Accumulation Distribution (AD). This series requires `linkedTo` option to
  35. * be set.
  36. *
  37. * @sample stock/indicators/accumulation-distribution
  38. * Accumulation/Distribution indicator
  39. *
  40. * @extends plotOptions.sma
  41. * @since 6.0.0
  42. * @product highstock
  43. * @requires stock/indicators/indicators
  44. * @requires stock/indicators/accumulation-distribution
  45. * @optionparent plotOptions.ad
  46. */
  47. {
  48. params: {
  49. /**
  50. * The id of volume series which is mandatory.
  51. * For example using OHLC data, volumeSeriesID='volume' means
  52. * the indicator will be calculated using OHLC and volume values.
  53. *
  54. * @since 6.0.0
  55. */
  56. volumeSeriesID: 'volume'
  57. }
  58. },
  59. /**
  60. * @lends Highcharts.Series#
  61. */
  62. {
  63. nameComponents: false,
  64. nameBase: 'Accumulation/Distribution',
  65. getValues: function (series, params) {
  66. var period = params.period, xVal = series.xData, yVal = series.yData, volumeSeriesID = params.volumeSeriesID, volumeSeries = series.chart.get(volumeSeriesID), yValVolume = volumeSeries && volumeSeries.yData, yValLen = yVal ? yVal.length : 0, AD = [], xData = [], yData = [], len, i, ADPoint;
  67. if (xVal.length <= period &&
  68. yValLen &&
  69. yVal[0].length !== 4) {
  70. return;
  71. }
  72. if (!volumeSeries) {
  73. H.error('Series ' +
  74. volumeSeriesID +
  75. ' not found! Check `volumeSeriesID`.', true, series.chart);
  76. return;
  77. }
  78. // i = period <-- skip first N-points
  79. // Calculate value one-by-one for each period in visible data
  80. for (i = period; i < yValLen; i++) {
  81. len = AD.length;
  82. ADPoint = populateAverage(xVal, yVal, yValVolume, i, period);
  83. if (len > 0) {
  84. ADPoint[1] += AD[len - 1][1];
  85. }
  86. AD.push(ADPoint);
  87. xData.push(ADPoint[0]);
  88. yData.push(ADPoint[1]);
  89. }
  90. return {
  91. values: AD,
  92. xData: xData,
  93. yData: yData
  94. };
  95. }
  96. });
  97. /**
  98. * A `AD` series. If the [type](#series.ad.type) option is not
  99. * specified, it is inherited from [chart.type](#chart.type).
  100. *
  101. * @extends series,plotOptions.ad
  102. * @since 6.0.0
  103. * @excluding dataParser, dataURL
  104. * @product highstock
  105. * @requires stock/indicators/indicators
  106. * @requires stock/indicators/accumulation-distribution
  107. * @apioption series.ad
  108. */
  109. ''; // add doclet above to transpiled file