ppo.src.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /**
  2. * @license Highstock JS v9.1.1 (2021-06-04)
  3. *
  4. * Indicator series type for Highcharts Stock
  5. *
  6. * (c) 2010-2021 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/ppo', ['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, 'Mixins/IndicatorRequired.js', [_modules['Core/Utilities.js']], function (U) {
  32. /**
  33. *
  34. * (c) 2010-2021 Daniel Studencki
  35. *
  36. * License: www.highcharts.com/license
  37. *
  38. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  39. *
  40. * */
  41. var error = U.error;
  42. /* eslint-disable no-invalid-this, valid-jsdoc */
  43. var requiredIndicatorMixin = {
  44. /**
  45. * Check whether given indicator is loaded,
  46. else throw error.
  47. * @private
  48. * @param {Highcharts.Indicator} indicator
  49. * Indicator constructor function.
  50. * @param {string} requiredIndicator
  51. * Required indicator type.
  52. * @param {string} type
  53. * Type of indicator where function was called (parent).
  54. * @param {Highcharts.IndicatorCallbackFunction} callback
  55. * Callback which is triggered if the given indicator is loaded.
  56. * Takes indicator as an argument.
  57. * @param {string} errMessage
  58. * Error message that will be logged in console.
  59. * @return {boolean}
  60. * Returns false when there is no required indicator loaded.
  61. */
  62. isParentLoaded: function (indicator,
  63. requiredIndicator,
  64. type,
  65. callback,
  66. errMessage) {
  67. if (indicator) {
  68. return callback ? callback(indicator) : true;
  69. }
  70. error(errMessage || this.generateMessage(type, requiredIndicator));
  71. return false;
  72. },
  73. /**
  74. * @private
  75. * @param {string} indicatorType
  76. * Indicator type
  77. * @param {string} required
  78. * Required indicator
  79. * @return {string}
  80. * Error message
  81. */
  82. generateMessage: function (indicatorType, required) {
  83. return 'Error: "' + indicatorType +
  84. '" indicator type requires "' + required +
  85. '" indicator loaded before. Please read docs: ' +
  86. 'https://api.highcharts.com/highstock/plotOptions.' +
  87. indicatorType;
  88. }
  89. };
  90. return requiredIndicatorMixin;
  91. });
  92. _registerModule(_modules, 'Stock/Indicators/PPO/PPOIndicator.js', [_modules['Mixins/IndicatorRequired.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (RequiredIndicatorMixin, SeriesRegistry, U) {
  93. /* *
  94. *
  95. * License: www.highcharts.com/license
  96. *
  97. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  98. *
  99. * */
  100. var __extends = (this && this.__extends) || (function () {
  101. var extendStatics = function (d,
  102. b) {
  103. extendStatics = Object.setPrototypeOf ||
  104. ({ __proto__: [] } instanceof Array && function (d,
  105. b) { d.__proto__ = b; }) ||
  106. function (d,
  107. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  108. return extendStatics(d, b);
  109. };
  110. return function (d, b) {
  111. extendStatics(d, b);
  112. function __() { this.constructor = d; }
  113. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  114. };
  115. })();
  116. var EMAIndicator = SeriesRegistry.seriesTypes.ema;
  117. var correctFloat = U.correctFloat,
  118. extend = U.extend,
  119. merge = U.merge,
  120. error = U.error;
  121. /* *
  122. *
  123. * Class
  124. *
  125. * */
  126. /**
  127. * The PPO series type.
  128. *
  129. * @private
  130. * @class
  131. * @name Highcharts.seriesTypes.ppo
  132. *
  133. * @augments Highcharts.Series
  134. */
  135. var PPOIndicator = /** @class */ (function (_super) {
  136. __extends(PPOIndicator, _super);
  137. function PPOIndicator() {
  138. var _this = _super !== null && _super.apply(this,
  139. arguments) || this;
  140. /* *
  141. *
  142. * Properties
  143. *
  144. * */
  145. _this.data = void 0;
  146. _this.options = void 0;
  147. _this.points = void 0;
  148. return _this;
  149. }
  150. /* *
  151. *
  152. * Functions
  153. *
  154. * */
  155. PPOIndicator.prototype.init = function () {
  156. var args = arguments,
  157. ctx = this;
  158. RequiredIndicatorMixin.isParentLoaded(EMAIndicator, 'ema', ctx.type, function (indicator) {
  159. indicator.prototype.init.apply(ctx, args);
  160. return;
  161. });
  162. };
  163. PPOIndicator.prototype.getValues = function (series, params) {
  164. var periods = params.periods,
  165. index = params.index,
  166. // 0- date, 1- Percentage Price Oscillator
  167. PPO = [],
  168. xData = [],
  169. yData = [],
  170. periodsOffset,
  171. // Shorter Period EMA
  172. SPE,
  173. // Longer Period EMA
  174. LPE,
  175. oscillator,
  176. i;
  177. // Check if periods are correct
  178. if (periods.length !== 2 || periods[1] <= periods[0]) {
  179. error('Error: "PPO requires two periods. Notice, first period ' +
  180. 'should be lower than the second one."');
  181. return;
  182. }
  183. SPE = EMAIndicator.prototype.getValues.call(this, series, {
  184. index: index,
  185. period: periods[0]
  186. });
  187. LPE = EMAIndicator.prototype.getValues.call(this, series, {
  188. index: index,
  189. period: periods[1]
  190. });
  191. // Check if ema is calculated properly, if not skip
  192. if (!SPE || !LPE) {
  193. return;
  194. }
  195. periodsOffset = periods[1] - periods[0];
  196. for (i = 0; i < LPE.yData.length; i++) {
  197. oscillator = correctFloat((SPE.yData[i + periodsOffset] -
  198. LPE.yData[i]) /
  199. LPE.yData[i] *
  200. 100);
  201. PPO.push([LPE.xData[i], oscillator]);
  202. xData.push(LPE.xData[i]);
  203. yData.push(oscillator);
  204. }
  205. return {
  206. values: PPO,
  207. xData: xData,
  208. yData: yData
  209. };
  210. };
  211. /**
  212. * Percentage Price Oscillator. This series requires the
  213. * `linkedTo` option to be set and should be loaded after the
  214. * `stock/indicators/indicators.js` and `stock/indicators/ema.js`.
  215. *
  216. * @sample {highstock} stock/indicators/ppo
  217. * Percentage Price Oscillator
  218. *
  219. * @extends plotOptions.ema
  220. * @since 7.0.0
  221. * @product highstock
  222. * @excluding allAreas, colorAxis, joinBy, keys, navigatorOptions,
  223. * pointInterval, pointIntervalUnit, pointPlacement,
  224. * pointRange, pointStart, showInNavigator, stacking
  225. * @requires stock/indicators/indicators
  226. * @requires stock/indicators/ema
  227. * @requires stock/indicators/ppo
  228. * @optionparent plotOptions.ppo
  229. */
  230. PPOIndicator.defaultOptions = merge(EMAIndicator.defaultOptions, {
  231. /**
  232. * Paramters used in calculation of Percentage Price Oscillator series
  233. * points.
  234. *
  235. * @excluding period
  236. */
  237. params: {
  238. period: void 0,
  239. /**
  240. * Periods for Percentage Price Oscillator calculations.
  241. *
  242. * @type {Array<number>}
  243. * @default [12, 26]
  244. */
  245. periods: [12, 26]
  246. }
  247. });
  248. return PPOIndicator;
  249. }(EMAIndicator));
  250. extend(PPOIndicator.prototype, {
  251. nameBase: 'PPO',
  252. nameComponents: ['periods']
  253. });
  254. SeriesRegistry.registerSeriesType('ppo', PPOIndicator);
  255. /* *
  256. *
  257. * Default Export
  258. *
  259. * */
  260. /**
  261. * A `Percentage Price Oscillator` series. If the [type](#series.ppo.type)
  262. * option is not specified, it is inherited from [chart.type](#chart.type).
  263. *
  264. * @extends series,plotOptions.ppo
  265. * @since 7.0.0
  266. * @product highstock
  267. * @excluding allAreas, colorAxis, dataParser, dataURL, joinBy, keys,
  268. * navigatorOptions, pointInterval, pointIntervalUnit,
  269. * pointPlacement, pointRange, pointStart, showInNavigator, stacking
  270. * @requires stock/indicators/indicators
  271. * @requires stock/indicators/ema
  272. * @requires stock/indicators/ppo
  273. * @apioption series.ppo
  274. */
  275. ''; // to include the above in the js output
  276. return PPOIndicator;
  277. });
  278. _registerModule(_modules, 'masters/indicators/ppo.src.js', [], function () {
  279. });
  280. }));