accumulation-distribution.src.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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/accumulation-distribution', ['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/AD/ADIndicator.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 error = U.error,
  56. extend = U.extend,
  57. merge = U.merge;
  58. /**
  59. * The AD series type.
  60. *
  61. * @private
  62. * @class
  63. * @name Highcharts.seriesTypes.ad
  64. *
  65. * @augments Highcharts.Series
  66. */
  67. var ADIndicator = /** @class */ (function (_super) {
  68. __extends(ADIndicator, _super);
  69. function ADIndicator() {
  70. /* *
  71. *
  72. * Static Properties
  73. *
  74. * */
  75. var _this = _super !== null && _super.apply(this,
  76. arguments) || this;
  77. /* *
  78. *
  79. * Properties
  80. *
  81. * */
  82. _this.data = void 0;
  83. _this.options = void 0;
  84. _this.points = void 0;
  85. return _this;
  86. }
  87. /* *
  88. *
  89. * Static Functions
  90. *
  91. * */
  92. ADIndicator.populateAverage = function (xVal, yVal, yValVolume, i, _period) {
  93. var high = yVal[i][1],
  94. low = yVal[i][2],
  95. close = yVal[i][3],
  96. volume = yValVolume[i],
  97. adY = close === high && close === low || high === low ?
  98. 0 :
  99. ((2 * close - low - high) / (high - low)) * volume,
  100. adX = xVal[i];
  101. return [adX, adY];
  102. };
  103. /* *
  104. *
  105. * Functions
  106. *
  107. * */
  108. ADIndicator.prototype.getValues = function (series, params) {
  109. var period = params.period,
  110. xVal = series.xData,
  111. yVal = series.yData,
  112. volumeSeriesID = params.volumeSeriesID,
  113. volumeSeries = series.chart.get(volumeSeriesID),
  114. yValVolume = volumeSeries && volumeSeries.yData,
  115. yValLen = yVal ? yVal.length : 0,
  116. AD = [],
  117. xData = [],
  118. yData = [],
  119. len,
  120. i,
  121. ADPoint;
  122. if (xVal.length <= period &&
  123. yValLen &&
  124. yVal[0].length !== 4) {
  125. return;
  126. }
  127. if (!volumeSeries) {
  128. error('Series ' +
  129. volumeSeriesID +
  130. ' not found! Check `volumeSeriesID`.', true, series.chart);
  131. return;
  132. }
  133. // i = period <-- skip first N-points
  134. // Calculate value one-by-one for each period in visible data
  135. for (i = period; i < yValLen; i++) {
  136. len = AD.length;
  137. ADPoint = ADIndicator.populateAverage(xVal, yVal, yValVolume, i, period);
  138. if (len > 0) {
  139. ADPoint[1] += AD[len - 1][1];
  140. }
  141. AD.push(ADPoint);
  142. xData.push(ADPoint[0]);
  143. yData.push(ADPoint[1]);
  144. }
  145. return {
  146. values: AD,
  147. xData: xData,
  148. yData: yData
  149. };
  150. };
  151. /**
  152. * Accumulation Distribution (AD). This series requires `linkedTo` option to
  153. * be set.
  154. *
  155. * @sample stock/indicators/accumulation-distribution
  156. * Accumulation/Distribution indicator
  157. *
  158. * @extends plotOptions.sma
  159. * @since 6.0.0
  160. * @product highstock
  161. * @requires stock/indicators/indicators
  162. * @requires stock/indicators/accumulation-distribution
  163. * @optionparent plotOptions.ad
  164. */
  165. ADIndicator.defaultOptions = merge(SMAIndicator.defaultOptions, {
  166. /**
  167. * @excluding index
  168. */
  169. params: {
  170. index: void 0,
  171. /**
  172. * The id of volume series which is mandatory.
  173. * For example using OHLC data, volumeSeriesID='volume' means
  174. * the indicator will be calculated using OHLC and volume values.
  175. *
  176. * @since 6.0.0
  177. */
  178. volumeSeriesID: 'volume'
  179. }
  180. });
  181. return ADIndicator;
  182. }(SMAIndicator));
  183. extend(ADIndicator.prototype, {
  184. nameComponents: false,
  185. nameBase: 'Accumulation/Distribution'
  186. });
  187. SeriesRegistry.registerSeriesType('ad', ADIndicator);
  188. /* *
  189. *
  190. * Default Export
  191. *
  192. * */
  193. /* *
  194. *
  195. * API Options
  196. *
  197. * */
  198. /**
  199. * A `AD` series. If the [type](#series.ad.type) option is not
  200. * specified, it is inherited from [chart.type](#chart.type).
  201. *
  202. * @extends series,plotOptions.ad
  203. * @since 6.0.0
  204. * @excluding dataParser, dataURL
  205. * @product highstock
  206. * @requires stock/indicators/indicators
  207. * @requires stock/indicators/accumulation-distribution
  208. * @apioption series.ad
  209. */
  210. ''; // add doclet above to transpiled file
  211. return ADIndicator;
  212. });
  213. _registerModule(_modules, 'masters/indicators/accumulation-distribution.src.js', [], function () {
  214. });
  215. }));