ao.src.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /**
  2. * @license Highstock JS v8.0.0 (2019-12-10)
  3. *
  4. * Indicator series type for Highstock
  5. *
  6. * (c) 2010-2019 Wojciech Chmiel
  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/ao', ['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/ao.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  32. /* *
  33. *
  34. * License: www.highcharts.com/license
  35. *
  36. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  37. *
  38. * */
  39. var correctFloat = U.correctFloat, isArray = U.isArray;
  40. var noop = H.noop;
  41. /**
  42. * The AO series type
  43. *
  44. * @private
  45. * @class
  46. * @name Highcharts.seriesTypes.ao
  47. *
  48. * @augments Highcharts.Series
  49. */
  50. H.seriesType('ao', 'sma',
  51. /**
  52. * Awesome Oscillator. This series requires the `linkedTo` option to
  53. * be set and should be loaded after the `stock/indicators/indicators.js`
  54. *
  55. * @sample {highstock} stock/indicators/ao
  56. * Awesome
  57. *
  58. * @extends plotOptions.sma
  59. * @since 7.0.0
  60. * @product highstock
  61. * @excluding allAreas, colorAxis, joinBy, keys, navigatorOptions,
  62. * params, pointInterval, pointIntervalUnit, pointPlacement,
  63. * pointRange, pointStart, showInNavigator, stacking
  64. * @requires stock/indicators/indicators
  65. * @requires stock/indicators/ao
  66. * @optionparent plotOptions.ao
  67. */
  68. {
  69. /**
  70. * Color of the Awesome oscillator series bar that is greater than the
  71. * previous one. Note that if a `color` is defined, the `color`
  72. * takes precedence and the `greaterBarColor` is ignored.
  73. *
  74. * @sample {highstock} stock/indicators/ao/
  75. * greaterBarColor
  76. *
  77. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  78. * @since 7.0.0
  79. */
  80. greaterBarColor: '#06B535',
  81. /**
  82. * Color of the Awesome oscillator series bar that is lower than the
  83. * previous one. Note that if a `color` is defined, the `color`
  84. * takes precedence and the `lowerBarColor` is ignored.
  85. *
  86. * @sample {highstock} stock/indicators/ao/
  87. * lowerBarColor
  88. *
  89. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  90. * @since 7.0.0
  91. */
  92. lowerBarColor: '#F21313',
  93. threshold: 0,
  94. groupPadding: 0.2,
  95. pointPadding: 0.2,
  96. states: {
  97. hover: {
  98. halo: {
  99. size: 0
  100. }
  101. }
  102. }
  103. },
  104. /**
  105. * @lends Highcharts.Series#
  106. */
  107. {
  108. nameBase: 'AO',
  109. nameComponents: false,
  110. // Columns support:
  111. markerAttribs: noop,
  112. getColumnMetrics: H.seriesTypes.column.prototype.getColumnMetrics,
  113. crispCol: H.seriesTypes.column.prototype.crispCol,
  114. translate: H.seriesTypes.column.prototype.translate,
  115. drawPoints: H.seriesTypes.column.prototype.drawPoints,
  116. drawGraph: function () {
  117. var indicator = this, options = indicator.options, points = indicator.points, userColor = indicator.userOptions.color, positiveColor = options.greaterBarColor, negativeColor = options.lowerBarColor, firstPoint = points[0], i;
  118. if (!userColor && firstPoint) {
  119. firstPoint.color = positiveColor;
  120. for (i = 1; i < points.length; i++) {
  121. if (points[i].y > points[i - 1].y) {
  122. points[i].color = positiveColor;
  123. }
  124. else if (points[i].y < points[i - 1].y) {
  125. points[i].color = negativeColor;
  126. }
  127. else {
  128. points[i].color = points[i - 1].color;
  129. }
  130. }
  131. }
  132. },
  133. getValues: function (series) {
  134. var shortPeriod = 5, longPeriod = 34, xVal = series.xData || [], yVal = series.yData || [], yValLen = yVal.length, AO = [], // 0- date, 1- Awesome Oscillator
  135. xData = [], yData = [], high = 1, low = 2, shortSum = 0, longSum = 0, shortSMA, // Shorter Period SMA
  136. longSMA, // Longer Period SMA
  137. awesome, shortLastIndex, longLastIndex, price, i, j;
  138. if (xVal.length <= longPeriod ||
  139. !isArray(yVal[0]) ||
  140. yVal[0].length !== 4) {
  141. return;
  142. }
  143. for (i = 0; i < longPeriod - 1; i++) {
  144. price = (yVal[i][high] + yVal[i][low]) / 2;
  145. if (i >= longPeriod - shortPeriod) {
  146. shortSum = correctFloat(shortSum + price);
  147. }
  148. longSum = correctFloat(longSum + price);
  149. }
  150. for (j = longPeriod - 1; j < yValLen; j++) {
  151. price = (yVal[j][high] + yVal[j][low]) / 2;
  152. shortSum = correctFloat(shortSum + price);
  153. longSum = correctFloat(longSum + price);
  154. shortSMA = shortSum / shortPeriod;
  155. longSMA = longSum / longPeriod;
  156. awesome = correctFloat(shortSMA - longSMA);
  157. AO.push([xVal[j], awesome]);
  158. xData.push(xVal[j]);
  159. yData.push(awesome);
  160. shortLastIndex = j + 1 - shortPeriod;
  161. longLastIndex = j + 1 - longPeriod;
  162. shortSum = correctFloat(shortSum -
  163. (yVal[shortLastIndex][high] +
  164. yVal[shortLastIndex][low]) / 2);
  165. longSum = correctFloat(longSum -
  166. (yVal[longLastIndex][high] +
  167. yVal[longLastIndex][low]) / 2);
  168. }
  169. return {
  170. values: AO,
  171. xData: xData,
  172. yData: yData
  173. };
  174. }
  175. });
  176. /**
  177. * An `AO` series. If the [type](#series.ao.type)
  178. * option is not specified, it is inherited from [chart.type](#chart.type).
  179. *
  180. * @extends series,plotOptions.ao
  181. * @since 7.0.0
  182. * @product highstock
  183. * @excluding allAreas, colorAxis, dataParser, dataURL, joinBy, keys,
  184. * navigatorOptions, pointInterval, pointIntervalUnit,
  185. * pointPlacement, pointRange, pointStart, showInNavigator, stacking
  186. * @requires stock/indicators/indicators
  187. * @requires stock/indicators/ao
  188. * @apioption series.ao
  189. */
  190. ''; // for including the above in the doclets
  191. });
  192. _registerModule(_modules, 'masters/indicators/ao.src.js', [], function () {
  193. });
  194. }));