ao.src.js 8.5 KB

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