highcharts
Version:
JavaScript charting framework
14 lines • 5.57 kB
JavaScript
!/**
* Highstock JS v13.0.1 (2026-08-17)
* @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
*/function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(e._Highcharts,e._Highcharts.SeriesRegistry):"function"==typeof define&&define.amd?define("highcharts/indicators/macd",["highcharts/highcharts"],function(e){return t(e,e.SeriesRegistry)}):"object"==typeof exports?exports["highcharts/indicators/macd"]=t(e._Highcharts,e._Highcharts.SeriesRegistry):e.Highcharts=t(e.Highcharts,e.Highcharts.SeriesRegistry)}("u"<typeof window?this:window,(e,t)=>(()=>{"use strict";var o={512(e){e.exports=t},944(t){t.exports=e}};let s={};function i(e){let t=s[e];if(void 0!==t)return t.exports;let r=s[e]={exports:{}};return o[e](r,r.exports,i),r.exports}i.n=e=>{let t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},i.d=(e,t)=>{if(Array.isArray(t))for(var o=0;o<t.length;){var s=t[o++],r=t[o++];i.o(e,s)?0===r&&o++:0===r?Object.defineProperty(e,s,{enumerable:!0,value:t[o++]}):Object.defineProperty(e,s,{enumerable:!0,get:r})}else for(var s in t)i.o(t,s)&&!i.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let r={};i.d(r,{default:()=>g});var n=i(944),l=i.n(n),a=i(512),p=i.n(a);let{noop:h}=l(),{sma:d}=p().seriesTypes;class c extends d{init(){p().seriesTypes.sma.prototype.init.apply(this,arguments);let e=this.color,t=this.colorIndex;this.options&&((0,n.defined)(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=e,this.colorIndex=t}toYData(e){return[e.y,e.signal,e.MACD]}translate(){let e=this,t=["plotSignal","plotMACD"];l().seriesTypes.column.prototype.translate.apply(e),e.points.forEach(function(o){[o.signal,o.MACD].forEach(function(s,i){null!==s&&(o[t[i]]=e.yAxis.toPixels(s,!0))})})}destroy(){this.graph=null,this.graphmacd=this.graphmacd&&this.graphmacd.destroy(),this.graphsignal=this.graphsignal&&this.graphsignal.destroy(),p().seriesTypes.sma.prototype.destroy.apply(this,arguments)}drawGraph(){let e=this,t=e.points,o=e.options,s=e.zones,i={options:{gapSize:o.gapSize}},r=[[],[]],l,a=t.length;for(;a--;)l=t[a],(0,n.defined)(l.plotMACD)&&r[0].push({plotX:l.plotX,plotY:l.plotMACD,isNull:!(0,n.defined)(l.plotMACD)}),(0,n.defined)(l.plotSignal)&&r[1].push({plotX:l.plotX,plotY:l.plotSignal,isNull:!(0,n.defined)(l.plotMACD)});["macd","signal"].forEach((t,s)=>{e.points=r[s],e.options=(0,n.merge)(o[`${t}Line`]?.styles||{},i),e.graph=e[`graph${t}`],e.zones=(e[`${t}Zones`].zones||[]).slice(e[`${t}Zones`].startIndex||0),p().seriesTypes.sma.prototype.drawGraph.call(e),e[`graph${t}`]=e.graph}),e.points=t,e.options=o,e.zones=s}applyZones(){let e=this.zones;this.zones=this.signalZones.zones,p().seriesTypes.sma.prototype.applyZones.call(this),this.graphmacd&&this.options.macdLine.zones.length&&this.graphmacd.hide(),this.zones=e}getValues(e,t){let o=t.longPeriod-t.shortPeriod,s=[],i=[],r=[],l,a,h,d=0,c=[];if(!(e.xData.length<t.longPeriod+t.signalPeriod)){for(h=0,l=p().seriesTypes.ema.prototype.getValues(e,{period:t.shortPeriod,index:t.index}),a=p().seriesTypes.ema.prototype.getValues(e,{period:t.longPeriod,index:t.index}),l=l.values,a=a.values;h<=l.length;h++)(0,n.defined)(a[h])&&(0,n.defined)(a[h][1])&&(0,n.defined)(l[h+o])&&(0,n.defined)(l[h+o][0])&&s.push([l[h+o][0],0,null,l[h+o][1]-a[h][1]]);for(h=0;h<s.length;h++)i.push(s[h][0]),r.push([0,null,s[h][3]]);for(h=0,c=(c=p().seriesTypes.ema.prototype.getValues({xData:i,yData:r},{period:t.signalPeriod,index:2})).values;h<s.length;h++)s[h][0]>=c[0][0]&&(s[h][2]=c[d][1],r[h]=[0,c[d][1],s[h][3]],null===s[h][3]?(s[h][1]=0,r[h][0]=0):(s[h][1]=(0,n.correctFloat)(s[h][3]-c[d][1]),r[h][0]=(0,n.correctFloat)(s[h][3]-c[d][1])),d++);return{values:s,xData:i,yData:r}}}}c.defaultOptions=(0,n.merge)(d.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}),(0,n.extend)(c.prototype,{nameComponents:["longPeriod","shortPeriod","signalPeriod"],pointArrayMap:["y","signal","MACD"],parallelArrays:["x","y","signal","MACD"],pointValKey:"y",markerAttribs:h,getColumnMetrics:l().seriesTypes.column.prototype.getColumnMetrics,crispCol:l().seriesTypes.column.prototype.crispCol,drawPoints:l().seriesTypes.column.prototype.drawPoints}),p().registerSeriesType("macd",c);let g=l();return r.default})());