accumulation-distribution.src.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /**
  2. * @license Highstock JS v8.2.0 (2020-08-20)
  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, 'Stock/Indicators/ADIndicator.js', [_modules['Core/Utilities.js']], function (U) {
  32. /* *
  33. *
  34. * License: www.highcharts.com/license
  35. *
  36. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  37. * */
  38. var error = U.error,
  39. seriesType = U.seriesType;
  40. /* eslint-disable valid-jsdoc */
  41. // Utils:
  42. /**
  43. * @private
  44. */
  45. function populateAverage(xVal, yVal, yValVolume, i) {
  46. var high = yVal[i][1],
  47. low = yVal[i][2],
  48. close = yVal[i][3],
  49. volume = yValVolume[i],
  50. adY = close === high && close === low || high === low ?
  51. 0 :
  52. ((2 * close - low - high) / (high - low)) * volume,
  53. adX = xVal[i];
  54. return [adX, adY];
  55. }
  56. /* eslint-enable valid-jsdoc */
  57. /**
  58. * The AD series type.
  59. *
  60. * @private
  61. * @class
  62. * @name Highcharts.seriesTypes.ad
  63. *
  64. * @augments Highcharts.Series
  65. */
  66. seriesType('ad', 'sma',
  67. /**
  68. * Accumulation Distribution (AD). This series requires `linkedTo` option to
  69. * be set.
  70. *
  71. * @sample stock/indicators/accumulation-distribution
  72. * Accumulation/Distribution indicator
  73. *
  74. * @extends plotOptions.sma
  75. * @since 6.0.0
  76. * @product highstock
  77. * @requires stock/indicators/indicators
  78. * @requires stock/indicators/accumulation-distribution
  79. * @optionparent plotOptions.ad
  80. */
  81. {
  82. params: {
  83. /**
  84. * The id of volume series which is mandatory.
  85. * For example using OHLC data, volumeSeriesID='volume' means
  86. * the indicator will be calculated using OHLC and volume values.
  87. *
  88. * @since 6.0.0
  89. */
  90. volumeSeriesID: 'volume'
  91. }
  92. },
  93. /**
  94. * @lends Highcharts.Series#
  95. */
  96. {
  97. nameComponents: false,
  98. nameBase: 'Accumulation/Distribution',
  99. getValues: function (series, params) {
  100. var period = params.period,
  101. xVal = series.xData,
  102. yVal = series.yData,
  103. volumeSeriesID = params.volumeSeriesID,
  104. volumeSeries = series.chart.get(volumeSeriesID),
  105. yValVolume = volumeSeries && volumeSeries.yData,
  106. yValLen = yVal ? yVal.length : 0,
  107. AD = [],
  108. xData = [],
  109. yData = [],
  110. len,
  111. i,
  112. ADPoint;
  113. if (xVal.length <= period &&
  114. yValLen &&
  115. yVal[0].length !== 4) {
  116. return;
  117. }
  118. if (!volumeSeries) {
  119. error('Series ' +
  120. volumeSeriesID +
  121. ' not found! Check `volumeSeriesID`.', true, series.chart);
  122. return;
  123. }
  124. // i = period <-- skip first N-points
  125. // Calculate value one-by-one for each period in visible data
  126. for (i = period; i < yValLen; i++) {
  127. len = AD.length;
  128. ADPoint = populateAverage(xVal, yVal, yValVolume, i, period);
  129. if (len > 0) {
  130. ADPoint[1] += AD[len - 1][1];
  131. }
  132. AD.push(ADPoint);
  133. xData.push(ADPoint[0]);
  134. yData.push(ADPoint[1]);
  135. }
  136. return {
  137. values: AD,
  138. xData: xData,
  139. yData: yData
  140. };
  141. }
  142. });
  143. /**
  144. * A `AD` series. If the [type](#series.ad.type) option is not
  145. * specified, it is inherited from [chart.type](#chart.type).
  146. *
  147. * @extends series,plotOptions.ad
  148. * @since 6.0.0
  149. * @excluding dataParser, dataURL
  150. * @product highstock
  151. * @requires stock/indicators/indicators
  152. * @requires stock/indicators/accumulation-distribution
  153. * @apioption series.ad
  154. */
  155. ''; // add doclet above to transpiled file
  156. });
  157. _registerModule(_modules, 'masters/indicators/accumulation-distribution.src.js', [], function () {
  158. });
  159. }));