ichimoku-kinko-hyo.src.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /**
  2. * @license Highstock JS v8.1.2 (2020-06-16)
  3. *
  4. * Indicator series type for Highstock
  5. *
  6. * (c) 2010-2019 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/ichimoku-kinko-hyo', ['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, 'indicators/ichimoku-kinko-hyo.src.js', [_modules['parts/Globals.js'], _modules['parts/Color.js'], _modules['parts/Utilities.js']], function (H, Color, U) {
  32. /* *
  33. *
  34. * License: www.highcharts.com/license
  35. *
  36. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  37. *
  38. * */
  39. /* eslint-enable @typescript-eslint/interface-name-prefix */
  40. var color = Color.parse;
  41. var defined = U.defined, isArray = U.isArray, merge = U.merge, objectEach = U.objectEach, seriesType = U.seriesType;
  42. var UNDEFINED, SMA = H.seriesTypes.sma;
  43. /* eslint-disable require-jsdoc */
  44. // Utils:
  45. function maxHigh(arr) {
  46. return arr.reduce(function (max, res) {
  47. return Math.max(max, res[1]);
  48. }, -Infinity);
  49. }
  50. function minLow(arr) {
  51. return arr.reduce(function (min, res) {
  52. return Math.min(min, res[2]);
  53. }, Infinity);
  54. }
  55. function highlowLevel(arr) {
  56. return {
  57. high: maxHigh(arr),
  58. low: minLow(arr)
  59. };
  60. }
  61. function getClosestPointRange(axis) {
  62. var closestDataRange, loopLength, distance, xData, i;
  63. axis.series.forEach(function (series) {
  64. if (series.xData) {
  65. xData = series.xData;
  66. loopLength = series.xIncrement ? 1 : xData.length - 1;
  67. for (i = loopLength; i > 0; i--) {
  68. distance = xData[i] - xData[i - 1];
  69. if (closestDataRange === UNDEFINED ||
  70. distance < closestDataRange) {
  71. closestDataRange = distance;
  72. }
  73. }
  74. }
  75. });
  76. return closestDataRange;
  77. }
  78. // Check two lines intersection (line a1-a2 and b1-b2)
  79. // Source: https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
  80. function checkLineIntersection(a1, a2, b1, b2) {
  81. if (a1 && a2 && b1 && b2) {
  82. var saX = a2.plotX - a1.plotX, // Auxiliary section a2-a1 X
  83. saY = a2.plotY - a1.plotY, // Auxiliary section a2-a1 Y
  84. sbX = b2.plotX - b1.plotX, // Auxiliary section b2-b1 X
  85. sbY = b2.plotY - b1.plotY, // Auxiliary section b2-b1 Y
  86. sabX = a1.plotX - b1.plotX, // Auxiliary section a1-b1 X
  87. sabY = a1.plotY - b1.plotY, // Auxiliary section a1-b1 Y
  88. // First degree Bézier parameters
  89. u, t;
  90. u = (-saY * sabX + saX * sabY) / (-sbX * saY + saX * sbY);
  91. t = (sbX * sabY - sbY * sabX) / (-sbX * saY + saX * sbY);
  92. if (u >= 0 && u <= 1 && t >= 0 && t <= 1) {
  93. return {
  94. plotX: a1.plotX + (t * saX),
  95. plotY: a1.plotY + (t * saY)
  96. };
  97. }
  98. }
  99. return false;
  100. }
  101. // Parameter opt (indicator options object) include indicator, points,
  102. // nextPoints, color, options, gappedExtend and graph properties
  103. function drawSenkouSpan(opt) {
  104. var indicator = opt.indicator;
  105. indicator.points = opt.points;
  106. indicator.nextPoints = opt.nextPoints;
  107. indicator.color = opt.color;
  108. indicator.options = merge(opt.options.senkouSpan.styles, opt.gap);
  109. indicator.graph = opt.graph;
  110. indicator.fillGraph = true;
  111. SMA.prototype.drawGraph.call(indicator);
  112. }
  113. // Data integrity in Ichimoku is different than default "averages":
  114. // Point: [undefined, value, value, ...] is correct
  115. // Point: [undefined, undefined, undefined, ...] is incorrect
  116. H.approximations['ichimoku-averages'] = function () {
  117. var ret = [], isEmptyRange;
  118. [].forEach.call(arguments, function (arr, i) {
  119. ret.push(H.approximations.average(arr));
  120. isEmptyRange = !isEmptyRange && typeof ret[i] === 'undefined';
  121. });
  122. // Return undefined when first elem. is undefined and let
  123. // sum method handle null (#7377)
  124. return isEmptyRange ? void 0 : ret;
  125. };
  126. /* eslint-enable require-jsdoc */
  127. /**
  128. * The IKH series type.
  129. *
  130. * @private
  131. * @class
  132. * @name Highcharts.seriesTypes.ikh
  133. *
  134. * @augments Highcharts.Series
  135. */
  136. seriesType('ikh', 'sma',
  137. /**
  138. * Ichimoku Kinko Hyo (IKH). This series requires `linkedTo` option to be
  139. * set.
  140. *
  141. * @sample stock/indicators/ichimoku-kinko-hyo
  142. * Ichimoku Kinko Hyo indicator
  143. *
  144. * @extends plotOptions.sma
  145. * @since 6.0.0
  146. * @excluding allAreas, colorAxis, compare, compareBase, joinBy, keys,
  147. * navigatorOptions, pointInterval, pointIntervalUnit,
  148. * pointPlacement, pointRange, pointStart, showInNavigator,
  149. * stacking
  150. * @product highstock
  151. * @requires stock/indicators/indicators
  152. * @requires stock/indicators/ichimoku-kinko-hyo
  153. * @optionparent plotOptions.ikh
  154. */
  155. {
  156. params: {
  157. period: 26,
  158. /**
  159. * The base period for Tenkan calculations.
  160. */
  161. periodTenkan: 9,
  162. /**
  163. * The base period for Senkou Span B calculations
  164. */
  165. periodSenkouSpanB: 52
  166. },
  167. marker: {
  168. enabled: false
  169. },
  170. tooltip: {
  171. pointFormat: '<span style="color:{point.color}">\u25CF</span> <b> {series.name}</b><br/>' +
  172. 'TENKAN SEN: {point.tenkanSen:.3f}<br/>' +
  173. 'KIJUN SEN: {point.kijunSen:.3f}<br/>' +
  174. 'CHIKOU SPAN: {point.chikouSpan:.3f}<br/>' +
  175. 'SENKOU SPAN A: {point.senkouSpanA:.3f}<br/>' +
  176. 'SENKOU SPAN B: {point.senkouSpanB:.3f}<br/>'
  177. },
  178. /**
  179. * The styles for Tenkan line
  180. */
  181. tenkanLine: {
  182. styles: {
  183. /**
  184. * Pixel width of the line.
  185. */
  186. lineWidth: 1,
  187. /**
  188. * Color of the line.
  189. *
  190. * @type {Highcharts.ColorString}
  191. */
  192. lineColor: void 0
  193. }
  194. },
  195. /**
  196. * The styles for Kijun line
  197. */
  198. kijunLine: {
  199. styles: {
  200. /**
  201. * Pixel width of the line.
  202. */
  203. lineWidth: 1,
  204. /**
  205. * Color of the line.
  206. *
  207. * @type {Highcharts.ColorString}
  208. */
  209. lineColor: void 0
  210. }
  211. },
  212. /**
  213. * The styles for Chikou line
  214. */
  215. chikouLine: {
  216. styles: {
  217. /**
  218. * Pixel width of the line.
  219. */
  220. lineWidth: 1,
  221. /**
  222. * Color of the line.
  223. *
  224. * @type {Highcharts.ColorString}
  225. */
  226. lineColor: void 0
  227. }
  228. },
  229. /**
  230. * The styles for Senkou Span A line
  231. */
  232. senkouSpanA: {
  233. styles: {
  234. /**
  235. * Pixel width of the line.
  236. */
  237. lineWidth: 1,
  238. /**
  239. * Color of the line.
  240. *
  241. * @type {Highcharts.ColorString}
  242. */
  243. lineColor: void 0
  244. }
  245. },
  246. /**
  247. * The styles for Senkou Span B line
  248. */
  249. senkouSpanB: {
  250. styles: {
  251. /**
  252. * Pixel width of the line.
  253. */
  254. lineWidth: 1,
  255. /**
  256. * Color of the line.
  257. *
  258. * @type {Highcharts.ColorString}
  259. */
  260. lineColor: void 0
  261. }
  262. },
  263. /**
  264. * The styles for area between Senkou Span A and B.
  265. */
  266. senkouSpan: {
  267. /**
  268. * Color of the area between Senkou Span A and B,
  269. * when Senkou Span A is above Senkou Span B. Note that if
  270. * a `style.fill` is defined, the `color` takes precedence and
  271. * the `style.fill` is ignored.
  272. *
  273. * @see [senkouSpan.styles.fill](#series.ikh.senkouSpan.styles.fill)
  274. *
  275. * @sample stock/indicators/ichimoku-kinko-hyo
  276. * Ichimoku Kinko Hyo color
  277. *
  278. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  279. * @since 7.0.0
  280. * @apioption plotOptions.ikh.senkouSpan.color
  281. */
  282. /**
  283. * Color of the area between Senkou Span A and B,
  284. * when Senkou Span A is under Senkou Span B.
  285. *
  286. * @sample stock/indicators/ikh-negative-color
  287. * Ichimoku Kinko Hyo negativeColor
  288. *
  289. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  290. * @since 7.0.0
  291. * @apioption plotOptions.ikh.senkouSpan.negativeColor
  292. */
  293. styles: {
  294. /**
  295. * Color of the area between Senkou Span A and B.
  296. *
  297. * @deprecated
  298. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  299. */
  300. fill: 'rgba(255, 0, 0, 0.5)'
  301. }
  302. },
  303. dataGrouping: {
  304. approximation: 'ichimoku-averages'
  305. }
  306. },
  307. /**
  308. * @lends Highcharts.Series#
  309. */
  310. {
  311. pointArrayMap: [
  312. 'tenkanSen',
  313. 'kijunSen',
  314. 'chikouSpan',
  315. 'senkouSpanA',
  316. 'senkouSpanB'
  317. ],
  318. pointValKey: 'tenkanSen',
  319. nameComponents: ['periodSenkouSpanB', 'period', 'periodTenkan'],
  320. init: function () {
  321. SMA.prototype.init.apply(this, arguments);
  322. // Set default color for lines:
  323. this.options = merge({
  324. tenkanLine: {
  325. styles: {
  326. lineColor: this.color
  327. }
  328. },
  329. kijunLine: {
  330. styles: {
  331. lineColor: this.color
  332. }
  333. },
  334. chikouLine: {
  335. styles: {
  336. lineColor: this.color
  337. }
  338. },
  339. senkouSpanA: {
  340. styles: {
  341. lineColor: this.color,
  342. fill: color(this.color).setOpacity(0.5).get()
  343. }
  344. },
  345. senkouSpanB: {
  346. styles: {
  347. lineColor: this.color,
  348. fill: color(this.color).setOpacity(0.5).get()
  349. }
  350. },
  351. senkouSpan: {
  352. styles: {
  353. fill: color(this.color).setOpacity(0.2).get()
  354. }
  355. }
  356. }, this.options);
  357. },
  358. toYData: function (point) {
  359. return [
  360. point.tenkanSen,
  361. point.kijunSen,
  362. point.chikouSpan,
  363. point.senkouSpanA,
  364. point.senkouSpanB
  365. ];
  366. },
  367. translate: function () {
  368. var indicator = this;
  369. SMA.prototype.translate.apply(indicator);
  370. indicator.points.forEach(function (point) {
  371. indicator.pointArrayMap.forEach(function (value) {
  372. if (defined(point[value])) {
  373. point['plot' + value] =
  374. indicator.yAxis.toPixels(point[value], true);
  375. // Add extra parameters for support tooltip in moved
  376. // lines
  377. point.plotY = point['plot' + value];
  378. point.tooltipPos = [
  379. point.plotX,
  380. point['plot' + value]
  381. ];
  382. point.isNull = false;
  383. }
  384. });
  385. });
  386. },
  387. // One does not simply
  388. // Render five linesZ
  389. // And an arearange
  390. // In just one series..
  391. drawGraph: function () {
  392. var indicator = this, mainLinePoints = (indicator.points), pointsLength = mainLinePoints.length, mainLineOptions = (indicator.options), mainLinePath = (indicator.graph), mainColor = indicator.color, gappedExtend = {
  393. options: {
  394. gapSize: mainLineOptions.gapSize
  395. }
  396. }, pointArrayMapLength = indicator.pointArrayMap.length, allIchimokuPoints = [[], [], [], [], [], []], ikhMap = {
  397. tenkanLine: allIchimokuPoints[0],
  398. kijunLine: allIchimokuPoints[1],
  399. chikouLine: allIchimokuPoints[2],
  400. senkouSpanA: allIchimokuPoints[3],
  401. senkouSpanB: allIchimokuPoints[4],
  402. senkouSpan: allIchimokuPoints[5]
  403. }, intersectIndexColl = [], senkouSpanOptions = indicator.options.senkouSpan, color = (senkouSpanOptions.color ||
  404. senkouSpanOptions.styles.fill), negativeColor = (senkouSpanOptions.negativeColor),
  405. // Points to create color and negativeColor senkouSpan
  406. points = [
  407. [],
  408. [] // Points negative color
  409. ],
  410. // For span, we need an access to the next points, used in
  411. // getGraphPath()
  412. nextPoints = [
  413. [],
  414. [] // NextPoints negative color
  415. ], lineIndex = 0, position, point, i, startIntersect, endIntersect, sectionPoints, sectionNextPoints, pointsPlotYSum, nextPointsPlotYSum, senkouSpanTempColor, concatArrIndex, j, k;
  416. indicator.ikhMap = ikhMap;
  417. // Generate points for all lines and spans lines:
  418. while (pointsLength--) {
  419. point = mainLinePoints[pointsLength];
  420. for (i = 0; i < pointArrayMapLength; i++) {
  421. position = indicator.pointArrayMap[i];
  422. if (defined(point[position])) {
  423. allIchimokuPoints[i].push({
  424. plotX: point.plotX,
  425. plotY: point['plot' + position],
  426. isNull: false
  427. });
  428. }
  429. }
  430. if (negativeColor &&
  431. pointsLength !== mainLinePoints.length - 1) {
  432. // Check if lines intersect
  433. var index = ikhMap.senkouSpanB.length - 1, intersect = checkLineIntersection(ikhMap.senkouSpanA[index - 1], ikhMap.senkouSpanA[index], ikhMap.senkouSpanB[index - 1], ikhMap.senkouSpanB[index]), intersectPointObj = {
  434. plotX: intersect.plotX,
  435. plotY: intersect.plotY,
  436. isNull: false,
  437. intersectPoint: true
  438. };
  439. if (intersect) {
  440. // Add intersect point to ichimoku points collection
  441. // Create senkouSpan sections
  442. ikhMap.senkouSpanA.splice(index, 0, intersectPointObj);
  443. ikhMap.senkouSpanB.splice(index, 0, intersectPointObj);
  444. intersectIndexColl.push(index);
  445. }
  446. }
  447. }
  448. // Modify options and generate lines:
  449. objectEach(ikhMap, function (values, lineName) {
  450. if (mainLineOptions[lineName] &&
  451. lineName !== 'senkouSpan') {
  452. // First line is rendered by default option
  453. indicator.points = allIchimokuPoints[lineIndex];
  454. indicator.options = merge(mainLineOptions[lineName].styles, gappedExtend);
  455. indicator.graph = indicator['graph' + lineName];
  456. indicator.fillGraph = false;
  457. indicator.color = mainColor;
  458. SMA.prototype.drawGraph.call(indicator);
  459. // Now save line
  460. indicator['graph' + lineName] = indicator.graph;
  461. }
  462. lineIndex++;
  463. });
  464. // Generate senkouSpan area:
  465. // If graphColection exist then remove svg
  466. // element and indicator property
  467. if (indicator.graphCollection) {
  468. indicator.graphCollection.forEach(function (graphName) {
  469. indicator[graphName].destroy();
  470. delete indicator[graphName];
  471. });
  472. }
  473. // Clean grapCollection or initialize it
  474. indicator.graphCollection = [];
  475. // When user set negativeColor property
  476. if (negativeColor &&
  477. ikhMap.senkouSpanA[0] &&
  478. ikhMap.senkouSpanB[0]) {
  479. // Add first and last point to senkouSpan area sections
  480. intersectIndexColl.unshift(0);
  481. intersectIndexColl.push(ikhMap.senkouSpanA.length - 1);
  482. // Populate points and nextPoints arrays
  483. for (j = 0; j < intersectIndexColl.length - 1; j++) {
  484. startIntersect = intersectIndexColl[j];
  485. endIntersect = intersectIndexColl[j + 1];
  486. sectionPoints = ikhMap.senkouSpanB.slice(startIntersect, endIntersect + 1);
  487. sectionNextPoints = ikhMap.senkouSpanA.slice(startIntersect, endIntersect + 1);
  488. // Add points to color or negativeColor arrays
  489. // Check the middle point (if exist)
  490. if (Math.floor(sectionPoints.length / 2) >= 1) {
  491. var x = Math.floor(sectionPoints.length / 2);
  492. // When middle points has equal values
  493. // Compare all ponints plotY value sum
  494. if (sectionPoints[x].plotY ===
  495. sectionNextPoints[x].plotY) {
  496. pointsPlotYSum = 0;
  497. nextPointsPlotYSum = 0;
  498. for (k = 0; k < sectionPoints.length; k++) {
  499. pointsPlotYSum +=
  500. sectionPoints[k].plotY;
  501. nextPointsPlotYSum +=
  502. sectionNextPoints[k].plotY;
  503. }
  504. concatArrIndex = (pointsPlotYSum > nextPointsPlotYSum ? 0 : 1);
  505. points[concatArrIndex] = (points[concatArrIndex].concat(sectionPoints));
  506. nextPoints[concatArrIndex] = (nextPoints[concatArrIndex].concat(sectionNextPoints));
  507. }
  508. else {
  509. // Compare middle point of the section
  510. concatArrIndex = (sectionPoints[x].plotY >
  511. sectionNextPoints[x].plotY ?
  512. 0 : 1);
  513. points[concatArrIndex] = (points[concatArrIndex].concat(sectionPoints));
  514. nextPoints[concatArrIndex] = (nextPoints[concatArrIndex].concat(sectionNextPoints));
  515. }
  516. }
  517. else {
  518. // Compare first point of the section
  519. concatArrIndex = (sectionPoints[0].plotY >
  520. sectionNextPoints[0].plotY ?
  521. 0 : 1);
  522. points[concatArrIndex] = (points[concatArrIndex].concat(sectionPoints));
  523. nextPoints[concatArrIndex] = (nextPoints[concatArrIndex].concat(sectionNextPoints));
  524. }
  525. }
  526. // Render color and negativeColor paths
  527. [
  528. 'graphsenkouSpanColor', 'graphsenkouSpanNegativeColor'
  529. ].forEach(function (areaName, i) {
  530. if (points[i].length && nextPoints[i].length) {
  531. senkouSpanTempColor = (i === 0) ?
  532. color : negativeColor;
  533. drawSenkouSpan({
  534. indicator: indicator,
  535. points: points[i],
  536. nextPoints: nextPoints[i],
  537. color: senkouSpanTempColor,
  538. options: mainLineOptions,
  539. gap: gappedExtend,
  540. graph: indicator[areaName]
  541. });
  542. // Now save line
  543. indicator[areaName] = indicator.graph;
  544. indicator.graphCollection.push(areaName);
  545. }
  546. });
  547. }
  548. else {
  549. // When user set only senkouSpan style.fill property
  550. drawSenkouSpan({
  551. indicator: indicator,
  552. points: ikhMap.senkouSpanB,
  553. nextPoints: ikhMap.senkouSpanA,
  554. color: color,
  555. options: mainLineOptions,
  556. gap: gappedExtend,
  557. graph: indicator.graphsenkouSpan
  558. });
  559. // Now save line
  560. indicator.graphsenkouSpan = indicator.graph;
  561. }
  562. // Clean temporary properties:
  563. delete indicator.nextPoints;
  564. delete indicator.fillGraph;
  565. // Restore options and draw the Tenkan line:
  566. indicator.points = mainLinePoints;
  567. indicator.options = mainLineOptions;
  568. indicator.graph = mainLinePath;
  569. },
  570. getGraphPath: function (points) {
  571. var indicator = this, path = [], spanA, spanAarr = [];
  572. points = points || this.points;
  573. // Render Senkou Span
  574. if (indicator.fillGraph && indicator.nextPoints) {
  575. spanA = SMA.prototype.getGraphPath.call(indicator,
  576. // Reverse points, so Senkou Span A will start from the end:
  577. indicator.nextPoints);
  578. spanA[0][0] = 'L';
  579. path = SMA.prototype.getGraphPath.call(indicator, points);
  580. spanAarr = spanA.slice(0, path.length);
  581. for (var i = spanAarr.length - 1; i >= 0; i--) {
  582. path.push(spanAarr[i]);
  583. }
  584. }
  585. else {
  586. path = SMA.prototype.getGraphPath.apply(indicator, arguments);
  587. }
  588. return path;
  589. },
  590. getValues: function (series, params) {
  591. var period = params.period, periodTenkan = params.periodTenkan, periodSenkouSpanB = params.periodSenkouSpanB, xVal = series.xData, yVal = series.yData, xAxis = series.xAxis, yValLen = (yVal && yVal.length) || 0, closestPointRange = getClosestPointRange(xAxis), IKH = [], xData = [], dateStart, date, slicedTSY, slicedKSY, slicedSSBY, pointTS, pointKS, pointSSB, i, TS, KS, CS, SSA, SSB;
  592. // Ikh requires close value
  593. if (xVal.length <= period ||
  594. !isArray(yVal[0]) ||
  595. yVal[0].length !== 4) {
  596. return;
  597. }
  598. // Add timestamps at the beginning
  599. dateStart = xVal[0] - (period * closestPointRange);
  600. for (i = 0; i < period; i++) {
  601. xData.push(dateStart + i * closestPointRange);
  602. }
  603. for (i = 0; i < yValLen; i++) {
  604. // Tenkan Sen
  605. if (i >= periodTenkan) {
  606. slicedTSY = yVal.slice(i - periodTenkan, i);
  607. pointTS = highlowLevel(slicedTSY);
  608. TS = (pointTS.high + pointTS.low) / 2;
  609. }
  610. if (i >= period) {
  611. slicedKSY = yVal.slice(i - period, i);
  612. pointKS = highlowLevel(slicedKSY);
  613. KS = (pointKS.high + pointKS.low) / 2;
  614. SSA = (TS + KS) / 2;
  615. }
  616. if (i >= periodSenkouSpanB) {
  617. slicedSSBY = yVal.slice(i - periodSenkouSpanB, i);
  618. pointSSB = highlowLevel(slicedSSBY);
  619. SSB = (pointSSB.high + pointSSB.low) / 2;
  620. }
  621. CS = yVal[i][3];
  622. date = xVal[i];
  623. if (IKH[i] === UNDEFINED) {
  624. IKH[i] = [];
  625. }
  626. if (IKH[i + period] === UNDEFINED) {
  627. IKH[i + period] = [];
  628. }
  629. IKH[i + period][0] = TS;
  630. IKH[i + period][1] = KS;
  631. IKH[i + period][2] = UNDEFINED;
  632. IKH[i][2] = CS;
  633. if (i <= period) {
  634. IKH[i + period][3] = UNDEFINED;
  635. IKH[i + period][4] = UNDEFINED;
  636. }
  637. if (IKH[i + 2 * period] === UNDEFINED) {
  638. IKH[i + 2 * period] = [];
  639. }
  640. IKH[i + 2 * period][3] = SSA;
  641. IKH[i + 2 * period][4] = SSB;
  642. xData.push(date);
  643. }
  644. // Add timestamps for further points
  645. for (i = 1; i <= period; i++) {
  646. xData.push(date + i * closestPointRange);
  647. }
  648. return {
  649. values: IKH,
  650. xData: xData,
  651. yData: IKH
  652. };
  653. }
  654. });
  655. /**
  656. * A `IKH` series. If the [type](#series.ikh.type) option is not
  657. * specified, it is inherited from [chart.type](#chart.type).
  658. *
  659. * @extends series,plotOptions.ikh
  660. * @since 6.0.0
  661. * @product highstock
  662. * @excluding dataParser, dataURL
  663. * @requires stock/indicators/indicators
  664. * @requires stock/indicators/ichimoku-kinko-hyo
  665. * @apioption series.ikh
  666. */
  667. ''; // add doclet above to transpiled file
  668. });
  669. _registerModule(_modules, 'masters/indicators/ichimoku-kinko-hyo.src.js', [], function () {
  670. });
  671. }));