UNPKG

highcharts

Version:
413 lines (395 loc) 14.2 kB
/** * @license Highstock JS v12.1.2 (2024-12-21) * @module highcharts/indicators/psar * @requires highcharts * @requires highcharts/modules/stock * * Parabolic SAR Indicator for Highcharts Stock * * (c) 2010-2024 Grzegorz Blachliński * * License: www.highcharts.com/license */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(root["_Highcharts"], root["_Highcharts"]["SeriesRegistry"]); else if(typeof define === 'function' && define.amd) define("highcharts/indicators/psar", ["highcharts/highcharts"], function (amd1) {return factory(amd1,amd1["SeriesRegistry"]);}); else if(typeof exports === 'object') exports["highcharts/indicators/psar"] = factory(root["_Highcharts"], root["_Highcharts"]["SeriesRegistry"]); else root["Highcharts"] = factory(root["Highcharts"], root["Highcharts"]["SeriesRegistry"]); })(typeof window === 'undefined' ? this : window, (__WEBPACK_EXTERNAL_MODULE__944__, __WEBPACK_EXTERNAL_MODULE__512__) => { return /******/ (() => { // webpackBootstrap /******/ "use strict"; /******/ var __webpack_modules__ = ({ /***/ 512: /***/ ((module) => { module.exports = __WEBPACK_EXTERNAL_MODULE__512__; /***/ }), /***/ 944: /***/ ((module) => { module.exports = __WEBPACK_EXTERNAL_MODULE__944__; /***/ }) /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ // no module.id needed /******/ // no module.loaded needed /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ /******/ /* webpack/runtime/compat get default export */ /******/ (() => { /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = (module) => { /******/ var getter = module && module.__esModule ? /******/ () => (module['default']) : /******/ () => (module); /******/ __webpack_require__.d(getter, { a: getter }); /******/ return getter; /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/define property getters */ /******/ (() => { /******/ // define getter functions for harmony exports /******/ __webpack_require__.d = (exports, definition) => { /******/ for(var key in definition) { /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ (() => { /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) /******/ })(); /******/ /************************************************************************/ var __webpack_exports__ = {}; // EXPORTS __webpack_require__.d(__webpack_exports__, { "default": () => (/* binding */ psar_src) }); // EXTERNAL MODULE: external {"amd":["highcharts/highcharts"],"commonjs":["highcharts"],"commonjs2":["highcharts"],"root":["Highcharts"]} var highcharts_commonjs_highcharts_commonjs2_highcharts_root_Highcharts_ = __webpack_require__(944); var highcharts_commonjs_highcharts_commonjs2_highcharts_root_Highcharts_default = /*#__PURE__*/__webpack_require__.n(highcharts_commonjs_highcharts_commonjs2_highcharts_root_Highcharts_); // EXTERNAL MODULE: external {"amd":["highcharts/highcharts","SeriesRegistry"],"commonjs":["highcharts","SeriesRegistry"],"commonjs2":["highcharts","SeriesRegistry"],"root":["Highcharts","SeriesRegistry"]} var highcharts_SeriesRegistry_commonjs_highcharts_SeriesRegistry_commonjs2_highcharts_SeriesRegistry_root_Highcharts_SeriesRegistry_ = __webpack_require__(512); var highcharts_SeriesRegistry_commonjs_highcharts_SeriesRegistry_commonjs2_highcharts_SeriesRegistry_root_Highcharts_SeriesRegistry_default = /*#__PURE__*/__webpack_require__.n(highcharts_SeriesRegistry_commonjs_highcharts_SeriesRegistry_commonjs2_highcharts_SeriesRegistry_root_Highcharts_SeriesRegistry_); ;// ./code/es-modules/Stock/Indicators/PSAR/PSARIndicator.js /* * * * Parabolic SAR indicator for Highcharts Stock * * (c) 2010-2024 Grzegorz Blachliński * * License: www.highcharts.com/license * * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!! * * */ const { sma: SMAIndicator } = (highcharts_SeriesRegistry_commonjs_highcharts_SeriesRegistry_commonjs2_highcharts_SeriesRegistry_root_Highcharts_SeriesRegistry_default()).seriesTypes; const { merge } = (highcharts_commonjs_highcharts_commonjs2_highcharts_root_Highcharts_default()); /* * * * Functions * * */ // Utils: /** * */ function toFixed(a, n) { return parseFloat(a.toFixed(n)); } /** * */ function calculateDirection(previousDirection, low, high, PSAR) { if ((previousDirection === 1 && low > PSAR) || (previousDirection === -1 && high > PSAR)) { return 1; } return -1; } /* * * Method for calculating acceleration factor * dir - direction * pDir - previous Direction * eP - extreme point * pEP - previous extreme point * inc - increment for acceleration factor * maxAcc - maximum acceleration factor * initAcc - initial acceleration factor */ /** * */ function getAccelerationFactor(dir, pDir, eP, pEP, pAcc, inc, maxAcc, initAcc) { if (dir === pDir) { if (dir === 1 && (eP > pEP)) { return (pAcc === maxAcc) ? maxAcc : toFixed(pAcc + inc, 2); } if (dir === -1 && (eP < pEP)) { return (pAcc === maxAcc) ? maxAcc : toFixed(pAcc + inc, 2); } return pAcc; } return initAcc; } /** * */ function getExtremePoint(high, low, previousDirection, previousExtremePoint) { if (previousDirection === 1) { return (high > previousExtremePoint) ? high : previousExtremePoint; } return (low < previousExtremePoint) ? low : previousExtremePoint; } /** * */ function getEPMinusPSAR(EP, PSAR) { return EP - PSAR; } /** * */ function getAccelerationFactorMultiply(accelerationFactor, EPMinusSAR) { return accelerationFactor * EPMinusSAR; } /* * * Method for calculating PSAR * pdir - previous direction * sDir - second previous Direction * PSAR - previous PSAR * pACCMultiply - previous acceleration factor multiply * sLow - second previous low * pLow - previous low * sHigh - second previous high * pHigh - previous high * pEP - previous extreme point */ /** * */ function getPSAR(pdir, sDir, PSAR, pACCMulti, sLow, pLow, pHigh, sHigh, pEP) { if (pdir === sDir) { if (pdir === 1) { return (PSAR + pACCMulti < Math.min(sLow, pLow)) ? PSAR + pACCMulti : Math.min(sLow, pLow); } return (PSAR + pACCMulti > Math.max(sHigh, pHigh)) ? PSAR + pACCMulti : Math.max(sHigh, pHigh); } return pEP; } /* * * * Class * * */ /** * The Parabolic SAR series type. * * @private * @class * @name Highcharts.seriesTypes.psar * * @augments Highcharts.Series */ class PSARIndicator extends SMAIndicator { constructor() { /* * * * Static Properties * * */ super(...arguments); this.nameComponents = void 0; } /* * * * Functions * * */ getValues(series, params) { const xVal = series.xData, yVal = series.yData, maxAccelerationFactor = params.maxAccelerationFactor, increment = params.increment, // Set initial acc factor (for every new trend!) initialAccelerationFactor = params.initialAccelerationFactor, decimals = params.decimals, index = params.index, PSARArr = [], xData = [], yData = []; let accelerationFactor = params.initialAccelerationFactor, direction, // Extreme point is the lowest low for falling and highest high // for rising psar - and we are starting with falling extremePoint = yVal[0][1], EPMinusPSAR, accelerationFactorMultiply, newDirection, previousDirection = 1, prevLow, prevPrevLow, prevHigh, prevPrevHigh, PSAR = yVal[0][2], newExtremePoint, high, low, ind; if (index >= yVal.length) { return; } for (ind = 0; ind < index; ind++) { extremePoint = Math.max(yVal[ind][1], extremePoint); PSAR = Math.min(yVal[ind][2], toFixed(PSAR, decimals)); } direction = (yVal[ind][1] > PSAR) ? 1 : -1; EPMinusPSAR = getEPMinusPSAR(extremePoint, PSAR); accelerationFactor = params.initialAccelerationFactor; accelerationFactorMultiply = getAccelerationFactorMultiply(accelerationFactor, EPMinusPSAR); PSARArr.push([xVal[index], PSAR]); xData.push(xVal[index]); yData.push(toFixed(PSAR, decimals)); for (ind = index + 1; ind < yVal.length; ind++) { prevLow = yVal[ind - 1][2]; prevPrevLow = yVal[ind - 2][2]; prevHigh = yVal[ind - 1][1]; prevPrevHigh = yVal[ind - 2][1]; high = yVal[ind][1]; low = yVal[ind][2]; // Null points break PSAR if (prevPrevLow !== null && prevPrevHigh !== null && prevLow !== null && prevHigh !== null && high !== null && low !== null) { PSAR = getPSAR(direction, previousDirection, PSAR, accelerationFactorMultiply, prevPrevLow, prevLow, prevHigh, prevPrevHigh, extremePoint); newExtremePoint = getExtremePoint(high, low, direction, extremePoint); newDirection = calculateDirection(previousDirection, low, high, PSAR); accelerationFactor = getAccelerationFactor(newDirection, direction, newExtremePoint, extremePoint, accelerationFactor, increment, maxAccelerationFactor, initialAccelerationFactor); EPMinusPSAR = getEPMinusPSAR(newExtremePoint, PSAR); accelerationFactorMultiply = getAccelerationFactorMultiply(accelerationFactor, EPMinusPSAR); PSARArr.push([xVal[ind], toFixed(PSAR, decimals)]); xData.push(xVal[ind]); yData.push(toFixed(PSAR, decimals)); previousDirection = direction; direction = newDirection; extremePoint = newExtremePoint; } } return { values: PSARArr, xData: xData, yData: yData }; } } /** * Parabolic SAR. This series requires `linkedTo` * option to be set and should be loaded * after `stock/indicators/indicators.js` file. * * @sample stock/indicators/psar * Parabolic SAR Indicator * * @extends plotOptions.sma * @since 6.0.0 * @product highstock * @requires stock/indicators/indicators * @requires stock/indicators/psar * @optionparent plotOptions.psar */ PSARIndicator.defaultOptions = merge(SMAIndicator.defaultOptions, { lineWidth: 0, marker: { enabled: true }, states: { hover: { lineWidthPlus: 0 } }, /** * @excluding period */ params: { period: void 0, // Unchangeable period, do not inherit (#15362) /** * The initial value for acceleration factor. * Acceleration factor is starting with this value * and increases by specified increment each time * the extreme point makes a new high. * AF can reach a maximum of maxAccelerationFactor, * no matter how long the uptrend extends. */ initialAccelerationFactor: 0.02, /** * The Maximum value for acceleration factor. * AF can reach a maximum of maxAccelerationFactor, * no matter how long the uptrend extends. */ maxAccelerationFactor: 0.2, /** * Acceleration factor increases by increment each time * the extreme point makes a new high. * * @since 6.0.0 */ increment: 0.02, /** * Index from which PSAR is starting calculation * * @since 6.0.0 */ index: 2, /** * Number of maximum decimals that are used in PSAR calculations. * * @since 6.0.0 */ decimals: 4 } }); highcharts_SeriesRegistry_commonjs_highcharts_SeriesRegistry_commonjs2_highcharts_SeriesRegistry_root_Highcharts_SeriesRegistry_default().registerSeriesType('psar', PSARIndicator); /* * * * Default Export * * */ /* harmony default export */ const PSAR_PSARIndicator = ((/* unused pure expression or super */ null && (PSARIndicator))); /* * * * API Options * * */ /** * A `PSAR` series. If the [type](#series.psar.type) option is not specified, it * is inherited from [chart.type](#chart.type). * * @extends series,plotOptions.psar * @since 6.0.0 * @product highstock * @excluding dataParser, dataURL * @requires stock/indicators/indicators * @requires stock/indicators/psar * @apioption series.psar */ ''; // To include the above in the js output ;// ./code/es-modules/masters/indicators/psar.src.js /* harmony default export */ const psar_src = ((highcharts_commonjs_highcharts_commonjs2_highcharts_root_Highcharts_default())); __webpack_exports__ = __webpack_exports__["default"]; /******/ return __webpack_exports__; /******/ })() ; });