UNPKG

highcharts

Version:
14 lines 5.42 kB
/** * Highstock JS v12.6.0 (2026-04-13) * @module highcharts/indicators/macd * @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 o from"../highcharts.js";var t={};t.n=o=>{var e=o&&o.__esModule?()=>o.default:()=>o;return t.d(e,{a:e}),e},t.d=(o,e)=>{for(var s in e)t.o(e,s)&&!t.o(o,s)&&Object.defineProperty(o,s,{enumerable:!0,get:e[s]})},t.o=(o,t)=>Object.prototype.hasOwnProperty.call(o,t);let e=o.default;var s=t.n(e);let i=o.default.SeriesRegistry;var n=t.n(i);let{doc:r,win:l}=s();function a(o,t){return o>1e14?o:parseFloat(o.toPrecision(t||14))}function p(o){return null!=o}function h(o){return c(o)&&"number"==typeof o.nodeType}function c(o,t){let e;return!!o&&"object"==typeof o&&(!t||"[object Array]"!==(e=Object.prototype.toString.call(o))&&"[object Array Iterator]"!==e)}function d(o,...t){let e,s=[o,...t],i={},n=function(o,t){return"object"!=typeof o&&(o={}),function(o,t,e){for(let e in o)Object.hasOwnProperty.call(o,e)&&t.call((0,o[e]),o[e],e,o)}(t,function(e,s){if("__proto__"!==s&&"constructor"!==s){let i;!c(e,!0)||(i=e?.constructor,c(e,!0)&&!h(e)&&i?.name&&"Object"!==i.name)||h(e)?o[s]=t[s]:o[s]=n(o[s]||{},e)}}),o};!0===o&&(i=s[1],s=Array.prototype.slice.call(s,2));let r=s.length;for(e=0;e<r;e++)i=n(i,s[e]);return i}Array.prototype.find;let{noop:y}=s(),{sma:g}=n().seriesTypes;class u extends g{init(){n().seriesTypes.sma.prototype.init.apply(this,arguments);let o=this.color,t=this.colorIndex;this.options&&(p(this.colorIndex)&&(this.options.signalLine?.styles&&!this.options.signalLine.styles.lineColor&&(this.options.colorIndex=this.colorIndex+1,this.getCyclic("color",void 0,this.chart.options.colors),this.options.signalLine.styles.lineColor=this.color),this.options.macdLine?.styles&&!this.options.macdLine.styles.lineColor&&(this.options.colorIndex=this.colorIndex+1,this.getCyclic("color",void 0,this.chart.options.colors),this.options.macdLine.styles.lineColor=this.color)),this.macdZones={zones:this.options.macdLine?.zones,startIndex:0},this.signalZones={zones:this.macdZones.zones?.concat(this.options.signalLine.zones),startIndex:this.macdZones.zones?.length}),this.color=o,this.colorIndex=t}toYData(o){return[o.y,o.signal,o.MACD]}translate(){let o=this,t=["plotSignal","plotMACD"];s().seriesTypes.column.prototype.translate.apply(o),o.points.forEach(function(e){[e.signal,e.MACD].forEach(function(s,i){null!==s&&(e[t[i]]=o.yAxis.toPixels(s,!0))})})}destroy(){this.graph=null,this.graphmacd=this.graphmacd&&this.graphmacd.destroy(),this.graphsignal=this.graphsignal&&this.graphsignal.destroy(),n().seriesTypes.sma.prototype.destroy.apply(this,arguments)}drawGraph(){let o=this,t=o.points,e=o.options,s=o.zones,i={options:{gapSize:e.gapSize}},r=[[],[]],l,a=t.length;for(;a--;)p((l=t[a]).plotMACD)&&r[0].push({plotX:l.plotX,plotY:l.plotMACD,isNull:!p(l.plotMACD)}),p(l.plotSignal)&&r[1].push({plotX:l.plotX,plotY:l.plotSignal,isNull:!p(l.plotMACD)});["macd","signal"].forEach((t,s)=>{o.points=r[s],o.options=d(e[`${t}Line`]?.styles||{},i),o.graph=o[`graph${t}`],o.zones=(o[`${t}Zones`].zones||[]).slice(o[`${t}Zones`].startIndex||0),n().seriesTypes.sma.prototype.drawGraph.call(o),o[`graph${t}`]=o.graph}),o.points=t,o.options=e,o.zones=s}applyZones(){let o=this.zones;this.zones=this.signalZones.zones,n().seriesTypes.sma.prototype.applyZones.call(this),this.graphmacd&&this.options.macdLine.zones.length&&this.graphmacd.hide(),this.zones=o}getValues(o,t){let e=t.longPeriod-t.shortPeriod,s=[],i=[],r=[],l,h,c,d=0,y=[];if(!(o.xData.length<t.longPeriod+t.signalPeriod)){for(c=0,l=n().seriesTypes.ema.prototype.getValues(o,{period:t.shortPeriod,index:t.index}),h=n().seriesTypes.ema.prototype.getValues(o,{period:t.longPeriod,index:t.index}),l=l.values,h=h.values;c<=l.length;c++)p(h[c])&&p(h[c][1])&&p(l[c+e])&&p(l[c+e][0])&&s.push([l[c+e][0],0,null,l[c+e][1]-h[c][1]]);for(c=0;c<s.length;c++)i.push(s[c][0]),r.push([0,null,s[c][3]]);for(c=0,y=(y=n().seriesTypes.ema.prototype.getValues({xData:i,yData:r},{period:t.signalPeriod,index:2})).values;c<s.length;c++)s[c][0]>=y[0][0]&&(s[c][2]=y[d][1],r[c]=[0,y[d][1],s[c][3]],null===s[c][3]?(s[c][1]=0,r[c][0]=0):(s[c][1]=a(s[c][3]-y[d][1]),r[c][0]=a(s[c][3]-y[d][1])),d++);return{values:s,xData:i,yData:r}}}}u.defaultOptions=d(g.defaultOptions,{params:{shortPeriod:12,longPeriod:26,signalPeriod:9,period:26},signalLine:{zones:[],styles:{lineWidth:1,lineColor:void 0}},macdLine:{zones:[],styles:{lineWidth:1,lineColor:void 0}},threshold:0,groupPadding:.1,pointPadding:.1,crisp:!1,states:{hover:{halo:{size:0}}},tooltip:{pointFormat:'<span style="color:{point.color}">●</span> <b> {series.name}</b><br/>Value: {point.MACD}<br/>Signal: {point.signal}<br/>Histogram: {point.y}<br/>'},dataGrouping:{approximation:"averages"},minPointLength:0}),function(o,t){let e;for(e in o||(o={}),t)o[e]=t[e]}(u.prototype,{nameComponents:["longPeriod","shortPeriod","signalPeriod"],pointArrayMap:["y","signal","MACD"],parallelArrays:["x","y","signal","MACD"],pointValKey:"y",markerAttribs:y,getColumnMetrics:s().seriesTypes.column.prototype.getColumnMetrics,crispCol:s().seriesTypes.column.prototype.crispCol,drawPoints:s().seriesTypes.column.prototype.drawPoints}),n().registerSeriesType("macd",u);let m=s();export{m as default};