obv.src.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /**
  2. * @license Highstock JS v9.1.1 (2021-06-04)
  3. *
  4. * Indicator series type for Highcharts Stock
  5. *
  6. * (c) 2010-2021 Karol Kolodziej
  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/obv', ['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/OBV/OBVIndicator.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. * */
  39. var __extends = (this && this.__extends) || (function () {
  40. var extendStatics = function (d,
  41. b) {
  42. extendStatics = Object.setPrototypeOf ||
  43. ({ __proto__: [] } instanceof Array && function (d,
  44. b) { d.__proto__ = b; }) ||
  45. function (d,
  46. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  47. return extendStatics(d, b);
  48. };
  49. return function (d, b) {
  50. extendStatics(d, b);
  51. function __() { this.constructor = d; }
  52. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  53. };
  54. })();
  55. var SMAIndicator = SeriesRegistry.seriesTypes.sma;
  56. var isNumber = U.isNumber,
  57. error = U.error,
  58. extend = U.extend,
  59. merge = U.merge;
  60. /* *
  61. *
  62. * Class
  63. *
  64. * */
  65. /**
  66. * The OBV series type.
  67. *
  68. * @private
  69. * @class
  70. * @name Highcharts.seriesTypes.obv
  71. *
  72. * @augments Highcharts.Series
  73. */
  74. var OBVIndicator = /** @class */ (function (_super) {
  75. __extends(OBVIndicator, _super);
  76. function OBVIndicator() {
  77. var _this = _super !== null && _super.apply(this,
  78. arguments) || this;
  79. /* *
  80. *
  81. * Properties
  82. *
  83. * */
  84. _this.data = void 0;
  85. _this.points = void 0;
  86. _this.options = void 0;
  87. return _this;
  88. }
  89. /* *
  90. *
  91. * Functions
  92. *
  93. * */
  94. OBVIndicator.prototype.getValues = function (series, params) {
  95. var volumeSeries = series.chart.get(params.volumeSeriesID),
  96. xVal = series.xData,
  97. yVal = series.yData,
  98. OBV = [],
  99. xData = [],
  100. yData = [],
  101. hasOHLC = !isNumber(yVal[0]);
  102. var OBVPoint = [],
  103. i = 1,
  104. previousOBV = 0,
  105. curentOBV = 0,
  106. previousClose = 0,
  107. curentClose = 0,
  108. volume;
  109. // Checks if volume series exists.
  110. if (volumeSeries) {
  111. volume = volumeSeries.yData;
  112. // Add first point and get close value.
  113. OBVPoint = [xVal[0], previousOBV];
  114. previousClose = hasOHLC ?
  115. yVal[0][3] : yVal[0];
  116. OBV.push(OBVPoint);
  117. xData.push(xVal[0]);
  118. yData.push(OBVPoint[1]);
  119. for (i; i < yVal.length; i++) {
  120. curentClose = hasOHLC ?
  121. yVal[i][3] : yVal[i];
  122. if (curentClose > previousClose) { // up
  123. curentOBV = previousOBV + volume[i];
  124. }
  125. else if (curentClose === previousClose) { // constant
  126. curentOBV = previousOBV;
  127. }
  128. else { // down
  129. curentOBV = previousOBV - volume[i];
  130. }
  131. // Add point.
  132. OBVPoint = [xVal[i], curentOBV];
  133. // Assign current as previous for next iteration.
  134. previousOBV = curentOBV;
  135. previousClose = curentClose;
  136. OBV.push(OBVPoint);
  137. xData.push(xVal[i]);
  138. yData.push(OBVPoint[1]);
  139. }
  140. }
  141. else {
  142. error('Series ' +
  143. params.volumeSeriesID +
  144. ' not found! Check `volumeSeriesID`.', true, series.chart);
  145. return;
  146. }
  147. return {
  148. values: OBV,
  149. xData: xData,
  150. yData: yData
  151. };
  152. };
  153. /**
  154. * On-Balance Volume (OBV) technical indicator. This series
  155. * requires the `linkedTo` option to be set and should be loaded after
  156. * the `stock/indicators/indicators.js` file. Through the `volumeSeriesID`
  157. * there also should be linked the volume series.
  158. *
  159. * @sample stock/indicators/obv
  160. * OBV indicator
  161. *
  162. * @extends plotOptions.sma
  163. * @since 9.1.0
  164. * @product highstock
  165. * @requires stock/indicators/indicators
  166. * @requires stock/indicators/obv
  167. * @excluding allAreas, colorAxis, joinBy, keys, navigatorOptions,
  168. * pointInterval, pointIntervalUnit, pointPlacement,
  169. * pointRange, pointStart, showInNavigator, stacking
  170. * @optionparent plotOptions.obv
  171. */
  172. OBVIndicator.defaultOptions = merge(SMAIndicator.defaultOptions, {
  173. marker: {
  174. enabled: false
  175. },
  176. /**
  177. * @excluding index, period
  178. */
  179. params: {
  180. // Index and period are unchangeable, do not inherit (#15362)
  181. index: void 0,
  182. period: void 0,
  183. /**
  184. * The id of another series to use its data as volume data for the
  185. * indiator calculation.
  186. */
  187. volumeSeriesID: 'volume'
  188. },
  189. tooltip: {
  190. valueDecimals: 0
  191. }
  192. });
  193. return OBVIndicator;
  194. }(SMAIndicator));
  195. extend(OBVIndicator.prototype, {
  196. nameComponents: void 0
  197. });
  198. SeriesRegistry.registerSeriesType('obv', OBVIndicator);
  199. /* *
  200. *
  201. * Default Export
  202. *
  203. * */
  204. /**
  205. * A `OBV` series. If the [type](#series.obv.type) option is not
  206. * specified, it is inherited from [chart.type](#chart.type).
  207. *
  208. * @extends series,plotOptions.obv
  209. * @since 9.1.0
  210. * @product highstock
  211. * @excluding dataParser, dataURL
  212. * @requires stock/indicators/indicators
  213. * @requires stock/indicators/obv
  214. * @apioption series.obv
  215. */
  216. ''; // to include the above in the js output
  217. return OBVIndicator;
  218. });
  219. _registerModule(_modules, 'masters/indicators/obv.src.js', [], function () {
  220. });
  221. }));