9 lines
5.6 KiB
JavaScript
9 lines
5.6 KiB
JavaScript
!/**
|
|
* Highcharts Stock JS v11.4.1 (2024-04-04)
|
|
*
|
|
* Indicator series type for Highcharts Stock
|
|
*
|
|
* (c) 2010-2024 Karol Kolodziej
|
|
*
|
|
* License: www.highcharts.com/license
|
|
*/function(e){"object"==typeof module&&module.exports?(e.default=e,module.exports=e):"function"==typeof define&&define.amd?define("highcharts/indicators/klinger",["highcharts","highcharts/modules/stock"],function(t){return e(t),e.Highcharts=t,e}):e("undefined"!=typeof Highcharts?Highcharts:void 0)}(function(e){"use strict";var t=e?e._modules:{};function i(e,t,i,o){e.hasOwnProperty(t)||(e[t]=o.apply(null,i),"function"==typeof CustomEvent&&window.dispatchEvent(new CustomEvent("HighchartsModuleLoaded",{detail:{path:t,module:e[t]}})))}i(t,"Stock/Indicators/MultipleLinesComposition.js",[t["Core/Series/SeriesRegistry.js"],t["Core/Utilities.js"]],function(e,t){var i;let{sma:{prototype:o}}=e.seriesTypes,{defined:s,error:r,merge:a}=t;return function(e){let t=["bottomLine"],i=["top","bottom"],n=["top"];function l(e){return"plot"+e.charAt(0).toUpperCase()+e.slice(1)}function p(e,t){let i=[];return(e.pointArrayMap||[]).forEach(e=>{e!==t&&i.push(l(e))}),i}function h(){let e=this,t=e.pointValKey,i=e.linesApiNames,n=e.areaLinesNames,h=e.points,u=e.options,c=e.graph,g={options:{gapSize:u.gapSize}},d=[],f=p(e,t),m=h.length,y;if(f.forEach((e,t)=>{for(d[t]=[];m--;)y=h[m],d[t].push({x:y.x,plotX:y.plotX,plotY:y[e],isNull:!s(y[e])});m=h.length}),e.userOptions.fillColor&&n.length){let t=d[f.indexOf(l(n[0]))],i=1===n.length?h:d[f.indexOf(l(n[1]))],s=e.color;e.points=i,e.nextPoints=t,e.color=e.userOptions.fillColor,e.options=a(h,g),e.graph=e.area,e.fillGraph=!0,o.drawGraph.call(e),e.area=e.graph,delete e.nextPoints,delete e.fillGraph,e.color=s}i.forEach((t,i)=>{d[i]?(e.points=d[i],u[t]?e.options=a(u[t].styles,g):r('Error: "There is no '+t+' in DOCS options declared. Check if linesApiNames are consistent with your DOCS line names."'),e.graph=e["graph"+t],o.drawGraph.call(e),e["graph"+t]=e.graph):r('Error: "'+t+" doesn't have equivalent in pointArrayMap. To many elements in linesApiNames relative to pointArrayMap.\"")}),e.points=h,e.options=u,e.graph=c,o.drawGraph.call(e)}function u(e){let t,i=[],s=[];if(e=e||this.points,this.fillGraph&&this.nextPoints){if((t=o.getGraphPath.call(this,this.nextPoints))&&t.length){t[0][0]="L",i=o.getGraphPath.call(this,e),s=t.slice(0,i.length);for(let e=s.length-1;e>=0;e--)i.push(s[e])}}else i=o.getGraphPath.apply(this,arguments);return i}function c(e){let t=[];return(this.pointArrayMap||[]).forEach(i=>{t.push(e[i])}),t}function g(){let e=this.pointArrayMap,t=[],i;t=p(this),o.translate.apply(this,arguments),this.points.forEach(o=>{e.forEach((e,s)=>{i=o[e],this.dataModify&&(i=this.dataModify.modifyValue(i)),null!==i&&(o[t[s]]=this.yAxis.toPixels(i,!0))})})}e.compose=function(e){let o=e.prototype;return o.linesApiNames=o.linesApiNames||t.slice(),o.pointArrayMap=o.pointArrayMap||i.slice(),o.pointValKey=o.pointValKey||"top",o.areaLinesNames=o.areaLinesNames||n.slice(),o.drawGraph=h,o.getGraphPath=u,o.toYData=c,o.translate=g,e}}(i||(i={})),i}),i(t,"Stock/Indicators/Klinger/KlingerIndicator.js",[t["Stock/Indicators/MultipleLinesComposition.js"],t["Core/Series/SeriesRegistry.js"],t["Core/Utilities.js"]],function(e,t,i){let{ema:o,sma:s}=t.seriesTypes,{correctFloat:r,error:a,extend:n,isArray:l,merge:p}=i;class h extends s{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,i=this.options,o=this.linkedParent,s=l(e)&&4===e.length,r=this.volumeSeries||(this.volumeSeries=t.get(i.params.volumeSeriesID));return r||a("Series "+i.params.volumeSeriesID+" not found! Check `volumeSeriesID`.",!0,o.chart),!!([o,r].every(function(e){return e&&e.xData&&e.xData.length>=i.params.slowAvgPeriod})&&s)}getCM(e,t,i,o,s){return r(t+(i===o?e:s))}getDM(e,t){return r(e-t)}getVolumeForce(e){let t=[],i=0,o,s=1,r=0,a=e[0][1]-e[0][2],n=0,l;for(;s<e.length;s++)l=this.calculateTrend(e,s),o=this.getDM(e[s][1],e[s][2]),i=this.getCM(r,o,l,n,a),t.push([this.volumeSeries.yData[s]*l*Math.abs(2*(o/i-1))*100]),n=l,r=i,a=o;return t}getEMA(e,t,i,s,r,a,n){return o.prototype.calculateEma(n||[],e,void 0===a?1:a,s,t,void 0===r?-1:r,i)}getSMA(e,t,i){return o.prototype.accumulatePeriodPoints(e,t,i)/e}getValues(e,t){let i=[],o=e.xData,s=e.yData,a=[],n=[],l=[],p,h=0,u=0,c,g,d,f=null;if(!this.isValidData(s[0]))return;let m=this.getVolumeForce(s),y=this.getSMA(t.fastAvgPeriod,0,m),A=this.getSMA(t.slowAvgPeriod,0,m),v=2/(t.fastAvgPeriod+1),P=2/(t.slowAvgPeriod+1);for(;h<s.length;h++)h>=t.fastAvgPeriod&&(g=u=this.getEMA(m,g,y,v,0,h,o)[1]),h>=t.slowAvgPeriod&&(d=c=this.getEMA(m,d,A,P,0,h,o)[1],l.push(p=r(u-c)),l.length>=t.signalPeriod&&(f=l.slice(-t.signalPeriod).reduce((e,t)=>e+t)/t.signalPeriod),i.push([o[h],p,f]),a.push(o[h]),n.push([p,f]));return{values:i,xData:a,yData:n}}}return h.defaultOptions=p(s.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/>'}}),n(h.prototype,{areaLinesNames:[],linesApiNames:["signalLine"],nameBase:"Klinger",nameComponents:["fastAvgPeriod","slowAvgPeriod"],pointArrayMap:["y","signal"],parallelArrays:["x","y","signal"],pointValKey:"y"}),e.compose(h),t.registerSeriesType("klinger",h),h}),i(t,"masters/indicators/klinger.src.js",[t["Core/Globals.js"]],function(e){return e})}); |