UNPKG

highcharts

Version:
14 lines 6.1 kB
/** * Highcharts Stock JS v12.6.0 (2026-04-13) * @module highcharts/indicators/klinger * @requires highcharts * @requires highcharts/modules/stock * * Indicator series type for Highcharts Stock * * (c) 2010-2026 Highsoft AS * Author: Karol Kołodziej * * A commercial license may be required depending on use. * See www.highcharts.com/license */import*as e from"../highcharts.js";var t,r={};r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let o=e.default;var i=r.n(o);let a=e.default.SeriesRegistry;var n=r.n(a);let{doc:s,win:l}=i();function p(e,t){return e>1e14?e:parseFloat(e.toPrecision(t||14))}function h(e){return c(e)&&"number"==typeof e.nodeType}function u(e){let t=Object.prototype.toString.call(e);return"[object Array]"===t||"[object Array Iterator]"===t}function c(e,t){return!!e&&"object"==typeof e&&(!t||!u(e))}function g(e,...t){let r,o=[e,...t],i={},a=function(e,t){return"object"!=typeof e&&(e={}),function(e,t,r){for(let r in e)Object.hasOwnProperty.call(e,r)&&t.call((0,e[r]),e[r],r,e)}(t,function(r,o){if("__proto__"!==o&&"constructor"!==o){let i;!c(r,!0)||(i=r?.constructor,c(r,!0)&&!h(r)&&i?.name&&"Object"!==i.name)||h(r)?e[o]=t[o]:e[o]=a(e[o]||{},r)}}),e};!0===e&&(i=o[1],o=Array.prototype.slice.call(o,2));let n=o.length;for(r=0;r<n;r++)i=a(i,o[r]);return i}Array.prototype.find;let{sma:{prototype:f}}=n().seriesTypes;!function(e){let t=["bottomLine"],r=["top","bottom"],i=["top"];function a(e){return"plot"+e.charAt(0).toUpperCase()+e.slice(1)}function n(e,t){let r=[];return(e.pointArrayMap||[]).forEach(e=>{e!==t&&r.push(a(e))}),r}function s(){let e=this,t=e.pointValKey,r=e.linesApiNames,i=e.areaLinesNames,s=e.points,l=e.options,p=e.graph,h={options:{gapSize:l.gapSize}},u=[],c=n(e,t),y=s.length,d;if(c.forEach((e,t)=>{for(u[t]=[];y--;)d=s[y],u[t].push({x:d.x,plotX:d.plotX,plotY:d[e],isNull:null==d[e]});y=s.length}),e.userOptions.fillColor&&i.length){let t=u[c.indexOf(a(i[0]))],r=1===i.length?s:u[c.indexOf(a(i[1]))],o=e.color;e.points=r,e.nextPoints=t,e.color=e.userOptions.fillColor,e.options=g(s,h),e.graph=e.area,e.fillGraph=!0,f.drawGraph.call(e),e.area=e.graph,delete e.nextPoints,delete e.fillGraph,e.color=o}r.forEach((t,r)=>{u[r]?(e.points=u[r],l[t]?e.options=g(l[t].styles,h):(0,o.error)('Error: "There is no '+t+' in DOCS options declared. Check if linesApiNames are consistent with your DOCS line names."'),e.graph=e["graph"+t],f.drawGraph.call(e),e["graph"+t]=e.graph):(0,o.error)('Error: "'+t+" doesn't have equivalent in pointArrayMap. To many elements in linesApiNames relative to pointArrayMap.\"")}),e.points=s,e.options=l,e.graph=p,f.drawGraph.call(e)}function l(e){let t,r=[],o=[];if(e=e||this.points,this.fillGraph&&this.nextPoints){if((t=f.getGraphPath.call(this,this.nextPoints))&&t.length){t[0][0]="L",r=f.getGraphPath.call(this,e),o=t.slice(0,r.length);for(let e=o.length-1;e>=0;e--)r.push(o[e])}}else r=f.getGraphPath.apply(this,arguments);return r}function p(e){let t=[];return(this.pointArrayMap||[]).forEach(r=>{t.push(e[r])}),t}function h(){let e=this.pointArrayMap,t=[],r;t=n(this),f.translate.apply(this,arguments),this.points.forEach(o=>{e.forEach((e,i)=>{r=o[e],this.dataModify&&(r=this.dataModify.modifyValue(r)),null!==r&&(o[t[i]]=this.yAxis.toPixels(r,!0))})})}e.compose=function(e){let o=e.prototype;return o.linesApiNames=o.linesApiNames||t.slice(),o.pointArrayMap=o.pointArrayMap||r.slice(),o.pointValKey=o.pointValKey||"top",o.areaLinesNames=o.areaLinesNames||i.slice(),o.drawGraph=s,o.getGraphPath=l,o.toYData=p,o.translate=h,e}}(t||(t={}));let y=t,{ema:d,sma:m}=n().seriesTypes;class A extends m{calculateTrend(e,t){return e[t][1]+e[t][2]+e[t][3]>e[t-1][1]+e[t-1][2]+e[t-1][3]?1:-1}isValidData(e){let t=this.chart,r=this.options,i=this.linkedParent,a=u(e)&&4===e.length,n=this.volumeSeries||(this.volumeSeries=t.get(r.params.volumeSeriesID));return n||(0,o.error)("Series "+r.params.volumeSeriesID+" not found! Check `volumeSeriesID`.",!0,i.chart),!!([i,n].every(function(e){return e&&e.dataTable.rowCount>=r.params.slowAvgPeriod})&&a)}getCM(e,t,r,o,i){return p(t+(r===o?e:i))}getDM(e,t){return p(e-t)}getVolumeForce(e){let t=[],r=0,o,i=1,a=0,n=e[0][1]-e[0][2],s=0,l;for(;i<e.length;i++)l=this.calculateTrend(e,i),o=this.getDM(e[i][1],e[i][2]),r=this.getCM(a,o,l,s,n),t.push([this.volumeSeries.getColumn("y")[i]*l*Math.abs(2*(o/r-1))*100]),s=l,a=r,n=o;return t}getEMA(e,t,r,o,i,a,n){return d.prototype.calculateEma(n||[],e,void 0===a?1:a,o,t,void 0===i?-1:i,r)}getSMA(e,t,r){return d.prototype.accumulatePeriodPoints(e,t,r)/e}getValues(e,t){let r=[],o=e.xData,i=e.yData,a=[],n=[],s=[],l,h=0,u=0,c,g,f,y=null;if(!this.isValidData(i[0]))return;let d=this.getVolumeForce(i),m=this.getSMA(t.fastAvgPeriod,0,d),A=this.getSMA(t.slowAvgPeriod,0,d),v=2/(t.fastAvgPeriod+1),P=2/(t.slowAvgPeriod+1);for(;h<i.length;h++)h>=t.fastAvgPeriod&&(g=u=this.getEMA(d,g,m,v,0,h,o)[1]),h>=t.slowAvgPeriod&&(f=c=this.getEMA(d,f,A,P,0,h,o)[1],s.push(l=p(u-c)),s.length>=t.signalPeriod&&(y=s.slice(-t.signalPeriod).reduce((e,t)=>e+t)/t.signalPeriod),r.push([o[h],l,y]),a.push(o[h]),n.push([l,y]));return{values:r,xData:a,yData:n}}}A.defaultOptions=g(m.defaultOptions,{params:{fastAvgPeriod:34,slowAvgPeriod:55,signalPeriod:13,volumeSeriesID:"volume"},signalLine:{styles:{lineWidth:1,lineColor:"#ff0000"}},dataGrouping:{approximation:"averages"},tooltip:{pointFormat:'<span style="color: {point.color}">●</span><b> {series.name}</b><br/><span style="color: {point.color}">Klinger</span>: {point.y}<br/><span style="color: {point.series.options.signalLine.styles.lineColor}">Signal</span>: {point.signal}<br/>'}}),function(e,t){let r;for(r in e||(e={}),t)e[r]=t[r]}(A.prototype,{areaLinesNames:[],linesApiNames:["signalLine"],nameBase:"Klinger",nameComponents:["fastAvgPeriod","slowAvgPeriod"],pointArrayMap:["y","signal"],parallelArrays:["x","y","signal"],pointValKey:"y"}),y.compose(A),n().registerSeriesType("klinger",A);let v=i();export{v as default};