momentum.src.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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/momentum', ['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/MomentumIndicator.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. * */
  39. var isArray = U.isArray,
  40. seriesType = U.seriesType;
  41. /* eslint-disable require-jsdoc */
  42. function populateAverage(points, xVal, yVal, i, period) {
  43. var mmY = yVal[i - 1][3] - yVal[i - period - 1][3],
  44. mmX = xVal[i - 1];
  45. points.shift(); // remove point until range < period
  46. return [mmX, mmY];
  47. }
  48. /* eslint-enable require-jsdoc */
  49. /**
  50. * The Momentum series type.
  51. *
  52. * @private
  53. * @class
  54. * @name Highcharts.seriesTypes.momentum
  55. *
  56. * @augments Highcharts.Series
  57. */
  58. seriesType('momentum', 'sma',
  59. /**
  60. * Momentum. This series requires `linkedTo` option to be set.
  61. *
  62. * @sample stock/indicators/momentum
  63. * Momentum indicator
  64. *
  65. * @extends plotOptions.sma
  66. * @since 6.0.0
  67. * @product highstock
  68. * @requires stock/indicators/indicators
  69. * @requires stock/indicators/momentum
  70. * @optionparent plotOptions.momentum
  71. */
  72. {
  73. params: {
  74. period: 14
  75. }
  76. },
  77. /**
  78. * @lends Highcharts.Series#
  79. */
  80. {
  81. nameBase: 'Momentum',
  82. getValues: function (series, params) {
  83. var period = params.period,
  84. xVal = series.xData,
  85. yVal = series.yData,
  86. yValLen = yVal ? yVal.length : 0,
  87. xValue = xVal[0],
  88. yValue = yVal[0],
  89. MM = [],
  90. xData = [],
  91. yData = [],
  92. index,
  93. i,
  94. points,
  95. MMPoint;
  96. if (xVal.length <= period) {
  97. return;
  98. }
  99. // Switch index for OHLC / Candlestick / Arearange
  100. if (isArray(yVal[0])) {
  101. yValue = yVal[0][3];
  102. }
  103. else {
  104. return;
  105. }
  106. // Starting point
  107. points = [
  108. [xValue, yValue]
  109. ];
  110. // Calculate value one-by-one for each period in visible data
  111. for (i = (period + 1); i < yValLen; i++) {
  112. MMPoint = populateAverage(points, xVal, yVal, i, period, index);
  113. MM.push(MMPoint);
  114. xData.push(MMPoint[0]);
  115. yData.push(MMPoint[1]);
  116. }
  117. MMPoint = populateAverage(points, xVal, yVal, i, period, index);
  118. MM.push(MMPoint);
  119. xData.push(MMPoint[0]);
  120. yData.push(MMPoint[1]);
  121. return {
  122. values: MM,
  123. xData: xData,
  124. yData: yData
  125. };
  126. }
  127. });
  128. /**
  129. * A `Momentum` series. If the [type](#series.momentum.type) option is not
  130. * specified, it is inherited from [chart.type](#chart.type).
  131. *
  132. * @extends series,plotOptions.momentum
  133. * @since 6.0.0
  134. * @excluding dataParser, dataURL
  135. * @product highstock
  136. * @requires stock/indicators/indicators
  137. * @requires stock/indicators/momentum
  138. * @apioption series.momentum
  139. */
  140. ''; // to include the above in the js output
  141. });
  142. _registerModule(_modules, 'masters/indicators/momentum.src.js', [], function () {
  143. });
  144. }));