accumulation-distribution.src.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /**
  2. * @license Highstock JS v9.0.1 (2021-02-16)
  3. *
  4. * Indicator series type for Highstock
  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. params: {
  167. /**
  168. * The id of volume series which is mandatory.
  169. * For example using OHLC data, volumeSeriesID='volume' means
  170. * the indicator will be calculated using OHLC and volume values.
  171. *
  172. * @since 6.0.0
  173. */
  174. volumeSeriesID: 'volume'
  175. }
  176. });
  177. return ADIndicator;
  178. }(SMAIndicator));
  179. extend(ADIndicator.prototype, {
  180. nameComponents: false,
  181. nameBase: 'Accumulation/Distribution'
  182. });
  183. SeriesRegistry.registerSeriesType('ad', ADIndicator);
  184. /* *
  185. *
  186. * Default Export
  187. *
  188. * */
  189. /* *
  190. *
  191. * API Options
  192. *
  193. * */
  194. /**
  195. * A `AD` series. If the [type](#series.ad.type) option is not
  196. * specified, it is inherited from [chart.type](#chart.type).
  197. *
  198. * @extends series,plotOptions.ad
  199. * @since 6.0.0
  200. * @excluding dataParser, dataURL
  201. * @product highstock
  202. * @requires stock/indicators/indicators
  203. * @requires stock/indicators/accumulation-distribution
  204. * @apioption series.ad
  205. */
  206. ''; // add doclet above to transpiled file
  207. return ADIndicator;
  208. });
  209. _registerModule(_modules, 'masters/indicators/accumulation-distribution.src.js', [], function () {
  210. });
  211. }));