williams-r.src.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 '../parts/Globals.js';
  10. import U from '../parts/Utilities.js';
  11. var isArray = U.isArray;
  12. import reduceArrayMixin from '../mixins/reduce-array.js';
  13. var getArrayExtremes = reduceArrayMixin.getArrayExtremes;
  14. /**
  15. * The Williams %R series type.
  16. *
  17. * @private
  18. * @class
  19. * @name Highcharts.seriesTypes.williamsr
  20. *
  21. * @augments Highcharts.Series
  22. */
  23. H.seriesType('williamsr', 'sma',
  24. /**
  25. * Williams %R. This series requires the `linkedTo` option to be
  26. * set and should be loaded after the `stock/indicators/indicators.js`.
  27. *
  28. * @sample {highstock} stock/indicators/williams-r
  29. * Williams %R
  30. *
  31. * @extends plotOptions.sma
  32. * @since 7.0.0
  33. * @product highstock
  34. * @excluding allAreas, colorAxis, joinBy, keys, navigatorOptions,
  35. * pointInterval, pointIntervalUnit, pointPlacement,
  36. * pointRange, pointStart, showInNavigator, stacking
  37. * @requires stock/indicators/indicators
  38. * @requires stock/indicators/williams-r
  39. * @optionparent plotOptions.williamsr
  40. */
  41. {
  42. /**
  43. * Paramters used in calculation of Williams %R series points.
  44. * @excluding index
  45. */
  46. params: {
  47. /**
  48. * Period for Williams %R oscillator
  49. */
  50. period: 14
  51. }
  52. },
  53. /**
  54. * @lends Highcharts.Series#
  55. */
  56. {
  57. nameBase: 'Williams %R',
  58. getValues: function (series, params) {
  59. var period = params.period, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0, WR = [], // 0- date, 1- Williams %R
  60. xData = [], yData = [], slicedY, close = 3, low = 2, high = 1, extremes, R, HH, // Highest high value in period
  61. LL, // Lowest low value in period
  62. CC, // Current close value
  63. i;
  64. // Williams %R requires close value
  65. if (xVal.length < period ||
  66. !isArray(yVal[0]) ||
  67. yVal[0].length !== 4) {
  68. return;
  69. }
  70. // For a N-period, we start from N-1 point, to calculate Nth point
  71. // That is why we later need to comprehend slice() elements list
  72. // with (+1)
  73. for (i = period - 1; i < yValLen; i++) {
  74. slicedY = yVal.slice(i - period + 1, i + 1);
  75. extremes = getArrayExtremes(slicedY, low, high);
  76. LL = extremes[0];
  77. HH = extremes[1];
  78. CC = yVal[i][close];
  79. R = ((HH - CC) / (HH - LL)) * -100;
  80. if (xVal[i]) {
  81. WR.push([xVal[i], R]);
  82. xData.push(xVal[i]);
  83. yData.push(R);
  84. }
  85. }
  86. return {
  87. values: WR,
  88. xData: xData,
  89. yData: yData
  90. };
  91. }
  92. });
  93. /**
  94. * A `Williams %R Oscillator` series. If the [type](#series.williamsr.type)
  95. * option is not specified, it is inherited from [chart.type](#chart.type).
  96. *
  97. * @extends series,plotOptions.williamsr
  98. * @since 7.0.0
  99. * @product highstock
  100. * @excluding allAreas, colorAxis, dataParser, dataURL, joinBy, keys,
  101. * navigatorOptions, pointInterval, pointIntervalUnit,
  102. * pointPlacement, pointRange, pointStart, showInNavigator, stacking
  103. * @requires stock/indicators/indicators
  104. * @requires stock/indicators/williams-r
  105. * @apioption series.williamsr
  106. */
  107. ''; // adds doclets above to the transpiled file