accumulation-distribution.src.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /**
  2. * @license Highstock JS v8.0.0 (2019-12-10)
  3. *
  4. * Indicator series type for Highstock
  5. *
  6. * (c) 2010-2019 Sebastian Bochan
  7. *
  8. * License: www.highcharts.com/license
  9. */
  10. 'use strict';
  11. (function (factory) {
  12. if (typeof module === 'object' && module.exports) {
  13. factory['default'] = factory;
  14. module.exports = factory;
  15. } else if (typeof define === 'function' && define.amd) {
  16. define('highcharts/indicators/accumulation-distribution', ['highcharts', 'highcharts/modules/stock'], function (Highcharts) {
  17. factory(Highcharts);
  18. factory.Highcharts = Highcharts;
  19. return factory;
  20. });
  21. } else {
  22. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  23. }
  24. }(function (Highcharts) {
  25. var _modules = Highcharts ? Highcharts._modules : {};
  26. function _registerModule(obj, path, args, fn) {
  27. if (!obj.hasOwnProperty(path)) {
  28. obj[path] = fn.apply(null, args);
  29. }
  30. }
  31. _registerModule(_modules, 'indicators/accumulation-distribution.src.js', [_modules['parts/Globals.js']], function (H) {
  32. /* *
  33. *
  34. * License: www.highcharts.com/license
  35. *
  36. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  37. * */
  38. var seriesType = H.seriesType;
  39. /* eslint-disable valid-jsdoc */
  40. // Utils:
  41. /**
  42. * @private
  43. */
  44. function populateAverage(xVal, yVal, yValVolume, i) {
  45. var high = yVal[i][1], low = yVal[i][2], close = yVal[i][3], volume = yValVolume[i], adY = close === high && close === low || high === low ?
  46. 0 :
  47. ((2 * close - low - high) / (high - low)) * volume, adX = xVal[i];
  48. return [adX, adY];
  49. }
  50. /* eslint-enable valid-jsdoc */
  51. /**
  52. * The AD series type.
  53. *
  54. * @private
  55. * @class
  56. * @name Highcharts.seriesTypes.ad
  57. *
  58. * @augments Highcharts.Series
  59. */
  60. seriesType('ad', 'sma',
  61. /**
  62. * Accumulation Distribution (AD). This series requires `linkedTo` option to
  63. * be set.
  64. *
  65. * @sample stock/indicators/accumulation-distribution
  66. * Accumulation/Distribution indicator
  67. *
  68. * @extends plotOptions.sma
  69. * @since 6.0.0
  70. * @product highstock
  71. * @requires stock/indicators/indicators
  72. * @requires stock/indicators/accumulation-distribution
  73. * @optionparent plotOptions.ad
  74. */
  75. {
  76. params: {
  77. /**
  78. * The id of volume series which is mandatory.
  79. * For example using OHLC data, volumeSeriesID='volume' means
  80. * the indicator will be calculated using OHLC and volume values.
  81. *
  82. * @since 6.0.0
  83. */
  84. volumeSeriesID: 'volume'
  85. }
  86. },
  87. /**
  88. * @lends Highcharts.Series#
  89. */
  90. {
  91. nameComponents: false,
  92. nameBase: 'Accumulation/Distribution',
  93. getValues: function (series, params) {
  94. 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;
  95. if (xVal.length <= period &&
  96. yValLen &&
  97. yVal[0].length !== 4) {
  98. return;
  99. }
  100. if (!volumeSeries) {
  101. H.error('Series ' +
  102. volumeSeriesID +
  103. ' not found! Check `volumeSeriesID`.', true, series.chart);
  104. return;
  105. }
  106. // i = period <-- skip first N-points
  107. // Calculate value one-by-one for each period in visible data
  108. for (i = period; i < yValLen; i++) {
  109. len = AD.length;
  110. ADPoint = populateAverage(xVal, yVal, yValVolume, i, period);
  111. if (len > 0) {
  112. ADPoint[1] += AD[len - 1][1];
  113. }
  114. AD.push(ADPoint);
  115. xData.push(ADPoint[0]);
  116. yData.push(ADPoint[1]);
  117. }
  118. return {
  119. values: AD,
  120. xData: xData,
  121. yData: yData
  122. };
  123. }
  124. });
  125. /**
  126. * A `AD` series. If the [type](#series.ad.type) option is not
  127. * specified, it is inherited from [chart.type](#chart.type).
  128. *
  129. * @extends series,plotOptions.ad
  130. * @since 6.0.0
  131. * @excluding dataParser, dataURL
  132. * @product highstock
  133. * @requires stock/indicators/indicators
  134. * @requires stock/indicators/accumulation-distribution
  135. * @apioption series.ad
  136. */
  137. ''; // add doclet above to transpiled file
  138. });
  139. _registerModule(_modules, 'masters/indicators/accumulation-distribution.src.js', [], function () {
  140. });
  141. }));