SlowStochasticIndicator.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* *
  2. *
  3. * License: www.highcharts.com/license
  4. *
  5. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6. *
  7. * */
  8. 'use strict';
  9. import H from '../../Core/Globals.js';
  10. import U from '../../Core/Utilities.js';
  11. var seriesType = U.seriesType;
  12. import requiredIndicator from '../../Mixins/IndicatorRequired.js';
  13. var seriesTypes = H.seriesTypes;
  14. /**
  15. * The Slow Stochastic series type.
  16. *
  17. * @private
  18. * @class
  19. * @name Highcharts.seriesTypes.slowstochastic
  20. *
  21. * @augments Highcharts.Series
  22. */
  23. seriesType('slowstochastic', 'stochastic',
  24. /**
  25. * Slow Stochastic oscillator. This series requires the `linkedTo` option
  26. * to be set and should be loaded after `stock/indicators/indicators.js`
  27. * and `stock/indicators/stochastic.js` files.
  28. *
  29. * @sample stock/indicators/slow-stochastic
  30. * Slow Stochastic oscillator
  31. *
  32. * @extends plotOptions.stochastic
  33. * @since 8.0.0
  34. * @product highstock
  35. * @requires stock/indicators/indicators
  36. * @requires stock/indicators/stochastic
  37. * @requires stock/indicators/slowstochastic
  38. * @optionparent plotOptions.slowstochastic
  39. */
  40. {
  41. params: {
  42. /**
  43. * Periods for Slow Stochastic oscillator: [%K, %D, SMA(%D)].
  44. *
  45. * @type {Array<number,number,number>}
  46. * @default [14, 3, 3]
  47. */
  48. periods: [14, 3, 3]
  49. }
  50. },
  51. /**
  52. * @lends Highcharts.Series#
  53. */
  54. {
  55. nameBase: 'Slow Stochastic',
  56. init: function () {
  57. var args = arguments, ctx = this;
  58. requiredIndicator.isParentLoaded(H.seriesTypes.stochastic, 'stochastic', ctx.type, function (indicator) {
  59. indicator.prototype.init.apply(ctx, args);
  60. return;
  61. });
  62. },
  63. getValues: function (series, params) {
  64. var periods = params.periods, fastValues = seriesTypes.stochastic.prototype.getValues.call(this, series, params), slowValues = {
  65. values: [],
  66. xData: [],
  67. yData: []
  68. };
  69. var i = 0;
  70. if (!fastValues) {
  71. return;
  72. }
  73. slowValues.xData = fastValues.xData.slice(periods[1] - 1);
  74. var fastYData = fastValues.yData.slice(periods[1] - 1);
  75. // Get SMA(%D)
  76. var smoothedValues = seriesTypes.sma.prototype.getValues.call(this, {
  77. xData: slowValues.xData,
  78. yData: fastYData
  79. }, {
  80. index: 1,
  81. period: periods[2]
  82. });
  83. if (!smoothedValues) {
  84. return;
  85. }
  86. var xDataLen = slowValues.xData.length;
  87. // Format data
  88. for (; i < xDataLen; i++) {
  89. slowValues.yData[i] = [
  90. fastYData[i][1],
  91. smoothedValues.yData[i - periods[2] + 1] || null
  92. ];
  93. slowValues.values[i] = [
  94. slowValues.xData[i],
  95. fastYData[i][1],
  96. smoothedValues.yData[i - periods[2] + 1] || null
  97. ];
  98. }
  99. return slowValues;
  100. }
  101. });
  102. /**
  103. * A Slow Stochastic indicator. If the [type](#series.slowstochastic.type)
  104. * option is not specified, it is inherited from [chart.type](#chart.type).
  105. *
  106. * @extends series,plotOptions.slowstochastic
  107. * @since 8.0.0
  108. * @product highstock
  109. * @requires stock/indicators/indicators
  110. * @requires stock/indicators/stochastic
  111. * @requires stock/indicators/slowstochastic
  112. * @apioption series.slowstochastic
  113. */
  114. ''; // to include the above in the js output