UNPKG

highcharts

Version:
14 lines 7.13 kB
/** * Highstock JS v13.0.1 (2026-08-17) * @module highcharts/indicators/ichimoku-kinko-hyo * @requires highcharts * @requires highcharts/modules/stock * * Indicator series type for Highcharts Stock * * (c) 2010-2026 Highsoft AS * Author: Sebastian Bochan * * A commercial license may be required depending on use, * see www.highcharts.com/license */import*as e from"../highcharts.js";import*as o from"../modules/datagrouping.js";let t={};t.n=e=>{let o=e&&e.__esModule?()=>e.default:()=>e;return t.d(o,{a:o}),o},t.d=(e,o)=>{if(Array.isArray(o))for(var n=0;n<o.length;){var i=o[n++],l=o[n++];t.o(e,i)?0===l&&n++:0===l?Object.defineProperty(e,i,{enumerable:!0,value:o[n++]}):Object.defineProperty(e,i,{enumerable:!0,get:l})}else for(var i in o)t.o(o,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:o[i]})},t.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o);let n=e.default;var i=t.n(n);let l=o.default.dataGrouping.approximations;var p=t.n(l);let s=e.default.Color;var a=t.n(s);let r=e.default.SeriesRegistry;var h=t.n(r);let{parse:u}=a(),{sma:c}=h().seriesTypes;function g(e){return{high:e.reduce(function(e,o){return Math.max(e,o[1])},-1/0),low:e.reduce(function(e,o){return Math.min(e,o[2])},1/0)}}function f(e){let o=e.indicator;o.points=e.points,o.nextPoints=e.nextPoints,o.color=e.color,o.options=(0,n.merge)(e.options.senkouSpan.styles,e.gap),o.graph=e.graph,o.fillGraph=!0,h().seriesTypes.sma.prototype.drawGraph.call(o)}class k extends c{constructor(){super(...arguments),this.data=[],this.options={},this.points=[],this.graphCollection=[]}init(){super.init.apply(this,arguments),this.options=(0,n.merge)({tenkanLine:{styles:{lineColor:this.color}},kijunLine:{styles:{lineColor:this.color}},chikouLine:{styles:{lineColor:this.color}},senkouSpanA:{styles:{lineColor:this.color,fill:u(this.color).setOpacity(.5).get()}},senkouSpanB:{styles:{lineColor:this.color,fill:u(this.color).setOpacity(.5).get()}},senkouSpan:{styles:{fill:u(this.color).setOpacity(.2).get()}}},this.options)}toYData(e){return[e.tenkanSen,e.kijunSen,e.chikouSpan,e.senkouSpanA,e.senkouSpanB]}translate(){for(let e of(h().seriesTypes.sma.prototype.translate.apply(this),this.points))for(let o of this.pointArrayMap){let t=e[o];(0,n.isNumber)(t)&&(e["plot"+o]=this.yAxis.toPixels(t,!0),e.plotY=e["plot"+o],e.tooltipPos=[e.plotX,e["plot"+o]],e.isNull=!1)}}drawGraph(){let e=this,o=e.points,t=e.options,i=e.graph,l=e.color,p={options:{gapSize:t.gapSize}},s=e.pointArrayMap.length,a=[[],[],[],[],[],[]],r={tenkanLine:a[0],kijunLine:a[1],chikouLine:a[2],senkouSpanA:a[3],senkouSpanB:a[4],senkouSpan:a[5]},u=[],c=e.options.senkouSpan,g=c.color||c.styles.fill,k=c.negativeColor,d=[[],[]],S=[[],[]],y=o.length,m=0,v,A,C,x,P,Y,b,B,N,j,G,O,X;for(e.ikhMap=r;y--;){for(C=0,A=o[y];C<s;C++)v=e.pointArrayMap[C],(0,n.defined)(A[v])&&a[C].push({plotX:A.plotX,plotY:A["plot"+v],isNull:!1});if(k&&y!==o.length-1){let e=r.senkouSpanB.length-1,o=function(e,o,t,n){if(e&&o&&t&&n){let i=o.plotX-e.plotX,l=o.plotY-e.plotY,p=n.plotX-t.plotX,s=n.plotY-t.plotY,a=e.plotX-t.plotX,r=e.plotY-t.plotY,h=(-l*a+i*r)/(-p*l+i*s),u=(p*r-s*a)/(-p*l+i*s);if(h>=0&&h<=1&&u>=0&&u<=1)return{plotX:e.plotX+u*i,plotY:e.plotY+u*l}}}(r.senkouSpanA[e-1],r.senkouSpanA[e],r.senkouSpanB[e-1],r.senkouSpanB[e]);if(o){let t={plotX:o.plotX,plotY:o.plotY,isNull:!1,intersectPoint:!0};r.senkouSpanA.splice(e,0,t),r.senkouSpanB.splice(e,0,t),u.push(e)}}}if((0,n.objectEach)(r,(o,i)=>{t[i]&&"senkouSpan"!==i&&(e.points=a[m],e.options=(0,n.merge)(t[i].styles,p),e.graph=e["graph"+i],e.fillGraph=!1,e.color=l,h().seriesTypes.sma.prototype.drawGraph.call(e),e["graph"+i]=e.graph),m++}),e.graphCollection)for(let o of e.graphCollection)e[o].destroy(),delete e[o];if(e.graphCollection=[],k&&r.senkouSpanA[0]&&r.senkouSpanB[0]){for(u.unshift(0),u.push(r.senkouSpanA.length-1),O=0;O<u.length-1;O++)if(x=u[O],P=u[O+1],Y=r.senkouSpanB.slice(x,P+1),b=r.senkouSpanA.slice(x,P+1),Math.floor(Y.length/2)>=1){let e=Math.floor(Y.length/2);if(Y[e].plotY===b[e].plotY){for(X=0,B=0,N=0;X<Y.length;X++)B+=Y[X].plotY,N+=b[X].plotY;d[G=B>N?0:1]=d[G].concat(Y),S[G]=S[G].concat(b)}else d[G=Y[e].plotY>b[e].plotY?0:1]=d[G].concat(Y),S[G]=S[G].concat(b)}else d[G=Y[0].plotY>b[0].plotY?0:1]=d[G].concat(Y),S[G]=S[G].concat(b);["graphsenkouSpanColor","graphsenkouSpanNegativeColor"].forEach(function(o,n){d[n].length&&S[n].length&&(j=0===n?g:k,f({indicator:e,points:d[n],nextPoints:S[n],color:j,options:t,gap:p,graph:e[o]}),e[o]=e.graph,e.graphCollection.push(o))})}else f({indicator:e,points:r.senkouSpanB,nextPoints:r.senkouSpanA,color:g,options:t,gap:p,graph:e.graphsenkouSpan}),e.graphsenkouSpan=e.graph;delete e.nextPoints,delete e.fillGraph,e.points=o,e.options=t,e.graph=i,e.color=l}getGraphPath(e){let o=[],t,n=[];if(e=e||this.points,this.fillGraph&&this.nextPoints){if((t=h().seriesTypes.sma.prototype.getGraphPath.call(this,this.nextPoints))&&t.length){t[0][0]="L",o=h().seriesTypes.sma.prototype.getGraphPath.call(this,e),n=t.slice(0,o.length);for(let e=n.length-1;e>=0;e--)o.push(n[e])}}else o=h().seriesTypes.sma.prototype.getGraphPath.apply(this,arguments);return o}getValues(e,o){let t,i,l,p,s,a,r,h,u,c,f=o.period,k=o.periodTenkan,d=o.periodSenkouSpanB,S=e.xData,y=e.yData,m=e.xAxis,v=y&&y.length||0,A=(0,n.getClosestDistance)(m.series.map(e=>e.getColumn("x"))),C=[],x=[];if(S.length<=f||!(0,n.isArray)(y[0])||4!==y[0].length)return;let P=S[0]-f*A;for(s=0;s<f;s++)x.push(P+s*A);for(s=0;s<v;s++)s>=k&&(a=((i=g(y.slice(s-k,s))).high+i.low)/2),s>=f&&(u=(a+(r=((l=g(y.slice(s-f,s))).high+l.low)/2))/2),s>=d&&(c=((p=g(y.slice(s-d,s))).high+p.low)/2),h=y[s][3],t=S[s],void 0===C[s]&&(C[s]=[]),void 0===C[s+f-1]&&(C[s+f-1]=[]),C[s+f-1][0]=a,C[s+f-1][1]=r,C[s+f-1][2]=void 0,void 0===C[s+1]&&(C[s+1]=[]),C[s+1][2]=h,s<=f&&(C[s+f-1][3]=void 0,C[s+f-1][4]=void 0),void 0===C[s+2*f-2]&&(C[s+2*f-2]=[]),C[s+2*f-2][3]=u,C[s+2*f-2][4]=c,x.push(t);for(s=1;s<=f;s++)x.push(t+s*A);return{values:C,xData:x,yData:C}}}k.defaultOptions=(0,n.merge)(c.defaultOptions,{params:{index:void 0,period:26,periodTenkan:9,periodSenkouSpanB:52},marker:{enabled:!1},tooltip:{pointFormat:'<span style="color:{point.color}">●</span> <b> {series.name}</b><br/>TENKAN SEN: {point.tenkanSen:.3f}<br/>KIJUN SEN: {point.kijunSen:.3f}<br/>CHIKOU SPAN: {point.chikouSpan:.3f}<br/>SENKOU SPAN A: {point.senkouSpanA:.3f}<br/>SENKOU SPAN B: {point.senkouSpanB:.3f}<br/>'},tenkanLine:{styles:{lineWidth:1,lineColor:void 0}},kijunLine:{styles:{lineWidth:1,lineColor:void 0}},chikouLine:{styles:{lineWidth:1,lineColor:void 0}},senkouSpanA:{styles:{lineWidth:1,lineColor:void 0}},senkouSpanB:{styles:{lineWidth:1,lineColor:void 0}},senkouSpan:{styles:{fill:"rgba(255, 0, 0, 0.5)"}},dataGrouping:{approximation:"ichimoku-averages"}}),(0,n.extend)(k.prototype,{pointArrayMap:["tenkanSen","kijunSen","chikouSpan","senkouSpanA","senkouSpanB"],pointValKey:"tenkanSen",nameComponents:["periodSenkouSpanB","period","periodTenkan"]}),p()["ichimoku-averages"]=function(){let e,o=[];return[].forEach.call(arguments,function(t,n){o.push(p().average(t)),e=!e&&void 0===o[n]}),e?void 0:o},h().registerSeriesType("ikh",k);let d=i();export{d as default};