cci.src.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /**
  2. * @license Highstock JS v9.1.1 (2021-06-04)
  3. *
  4. * Indicator series type for Highcharts Stock
  5. *
  6. * (c) 2010-2021 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/cci', ['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/CCI/CCIIndicator.js', [_modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (SeriesRegistry, U) {
  32. /* *
  33. *
  34. * License: www.highcharts.com/license
  35. *
  36. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  37. * */
  38. var __extends = (this && this.__extends) || (function () {
  39. var extendStatics = function (d,
  40. b) {
  41. extendStatics = Object.setPrototypeOf ||
  42. ({ __proto__: [] } instanceof Array && function (d,
  43. b) { d.__proto__ = b; }) ||
  44. function (d,
  45. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  46. return extendStatics(d, b);
  47. };
  48. return function (d, b) {
  49. extendStatics(d, b);
  50. function __() { this.constructor = d; }
  51. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  52. };
  53. })();
  54. var SMAIndicator = SeriesRegistry.seriesTypes.sma;
  55. var isArray = U.isArray,
  56. merge = U.merge;
  57. /* eslint-disable valid-jsdoc */
  58. // Utils:
  59. /**
  60. * @private
  61. */
  62. function sumArray(array) {
  63. return array.reduce(function (prev, cur) {
  64. return prev + cur;
  65. }, 0);
  66. }
  67. /**
  68. * @private
  69. */
  70. function meanDeviation(arr, sma) {
  71. var len = arr.length,
  72. sum = 0,
  73. i;
  74. for (i = 0; i < len; i++) {
  75. sum += Math.abs(sma - (arr[i]));
  76. }
  77. return sum;
  78. }
  79. /* eslint-enable valid-jsdoc */
  80. /* *
  81. *
  82. * Class
  83. *
  84. * */
  85. /**
  86. * The CCI series type.
  87. *
  88. * @private
  89. * @class
  90. * @name Highcharts.seriesTypes.cci
  91. *
  92. * @augments Highcharts.Series
  93. */
  94. var CCIIndicator = /** @class */ (function (_super) {
  95. __extends(CCIIndicator, _super);
  96. function CCIIndicator() {
  97. var _this = _super !== null && _super.apply(this,
  98. arguments) || this;
  99. /* *
  100. *
  101. * Properties
  102. *
  103. * */
  104. _this.data = void 0;
  105. _this.points = void 0;
  106. _this.options = void 0;
  107. return _this;
  108. }
  109. /* *
  110. *
  111. * Functions
  112. *
  113. * */
  114. CCIIndicator.prototype.getValues = function (series, params) {
  115. var period = params.period,
  116. xVal = series.xData,
  117. yVal = series.yData,
  118. yValLen = yVal ? yVal.length : 0,
  119. TP = [],
  120. periodTP = [],
  121. range = 1,
  122. CCI = [],
  123. xData = [],
  124. yData = [],
  125. CCIPoint,
  126. p,
  127. len,
  128. smaTP,
  129. TPtemp,
  130. meanDev,
  131. i;
  132. // CCI requires close value
  133. if (xVal.length <= period ||
  134. !isArray(yVal[0]) ||
  135. yVal[0].length !== 4) {
  136. return;
  137. }
  138. // accumulate first N-points
  139. while (range < period) {
  140. p = yVal[range - 1];
  141. TP.push((p[1] + p[2] + p[3]) / 3);
  142. range++;
  143. }
  144. for (i = period; i <= yValLen; i++) {
  145. p = yVal[i - 1];
  146. TPtemp = (p[1] + p[2] + p[3]) / 3;
  147. len = TP.push(TPtemp);
  148. periodTP = TP.slice(len - period);
  149. smaTP = sumArray(periodTP) / period;
  150. meanDev = meanDeviation(periodTP, smaTP) / period;
  151. CCIPoint = ((TPtemp - smaTP) / (0.015 * meanDev));
  152. CCI.push([xVal[i - 1], CCIPoint]);
  153. xData.push(xVal[i - 1]);
  154. yData.push(CCIPoint);
  155. }
  156. return {
  157. values: CCI,
  158. xData: xData,
  159. yData: yData
  160. };
  161. };
  162. /**
  163. * Commodity Channel Index (CCI). This series requires `linkedTo` option to
  164. * be set.
  165. *
  166. * @sample stock/indicators/cci
  167. * CCI indicator
  168. *
  169. * @extends plotOptions.sma
  170. * @since 6.0.0
  171. * @product highstock
  172. * @requires stock/indicators/indicators
  173. * @requires stock/indicators/cci
  174. * @optionparent plotOptions.cci
  175. */
  176. CCIIndicator.defaultOptions = merge(SMAIndicator.defaultOptions, {
  177. /**
  178. * @excluding index
  179. */
  180. params: {
  181. index: void 0 // unused index, do not inherit (#15362)
  182. }
  183. });
  184. return CCIIndicator;
  185. }(SMAIndicator));
  186. SeriesRegistry.registerSeriesType('cci', CCIIndicator);
  187. /* *
  188. *
  189. * Default Export
  190. *
  191. * */
  192. /**
  193. * A `CCI` series. If the [type](#series.cci.type) option is not
  194. * specified, it is inherited from [chart.type](#chart.type).
  195. *
  196. * @extends series,plotOptions.cci
  197. * @since 6.0.0
  198. * @excluding dataParser, dataURL
  199. * @product highstock
  200. * @requires stock/indicators/indicators
  201. * @requires stock/indicators/cci
  202. * @apioption series.cci
  203. */
  204. ''; // to include the above in the js output
  205. return CCIIndicator;
  206. });
  207. _registerModule(_modules, 'masters/indicators/cci.src.js', [], function () {
  208. });
  209. }));