highcharts
Version:
JavaScript charting framework
14 lines • 6.04 kB
JavaScript
!/**
* 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
*/function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(t._Highcharts,t._Highcharts.SeriesRegistry):"function"==typeof define&&define.amd?define("highcharts/indicators/macd",["highcharts/highcharts"],function(t){return e(t,t.SeriesRegistry)}):"object"==typeof exports?exports["highcharts/indicators/macd"]=e(t._Highcharts,t._Highcharts.SeriesRegistry):t.Highcharts=e(t.Highcharts,t.Highcharts.SeriesRegistry)}("u"<typeof window?this:window,(t,e)=>(()=>{"use strict";var o={512:t=>{t.exports=e},944:e=>{e.exports=t}},s={};function i(t){var e=s[t];if(void 0!==e)return e.exports;var r=s[t]={exports:{}};return o[t](r,r.exports,i),r.exports}i.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return i.d(e,{a:e}),e},i.d=(t,e)=>{for(var o in e)i.o(e,o)&&!i.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var r={};i.d(r,{default:()=>P});var n=i(944),l=i.n(n),a=i(512),p=i.n(a);let{doc:h,win:c}=l();function d(t,e){return t>1e14?t:parseFloat(t.toPrecision(e||14))}function g(t){return null!=t}function y(t){return u(t)&&"number"==typeof t.nodeType}function u(t,e){let o;return!!t&&"object"==typeof t&&(!e||"[object Array]"!==(o=Object.prototype.toString.call(t))&&"[object Array Iterator]"!==o)}function m(t,...e){let o,s=[t,...e],i={},r=function(t,e){return"object"!=typeof t&&(t={}),function(t,e,o){for(let o in t)Object.hasOwnProperty.call(t,o)&&e.call((0,t[o]),t[o],o,t)}(e,function(o,s){if("__proto__"!==s&&"constructor"!==s){let i;!u(o,!0)||(i=o?.constructor,u(o,!0)&&!y(o)&&i?.name&&"Object"!==i.name)||y(o)?t[s]=e[s]:t[s]=r(t[s]||{},o)}}),t};!0===t&&(i=s[1],s=Array.prototype.slice.call(s,2));let n=s.length;for(o=0;o<n;o++)i=r(i,s[o]);return i}Array.prototype.find;let{noop:f}=l(),{sma:x}=p().seriesTypes;class C extends x{init(){p().seriesTypes.sma.prototype.init.apply(this,arguments);let t=this.color,e=this.colorIndex;this.options&&(g(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=t,this.colorIndex=e}toYData(t){return[t.y,t.signal,t.MACD]}translate(){let t=this,e=["plotSignal","plotMACD"];l().seriesTypes.column.prototype.translate.apply(t),t.points.forEach(function(o){[o.signal,o.MACD].forEach(function(s,i){null!==s&&(o[e[i]]=t.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 t=this,e=t.points,o=t.options,s=t.zones,i={options:{gapSize:o.gapSize}},r=[[],[]],n,l=e.length;for(;l--;)g((n=e[l]).plotMACD)&&r[0].push({plotX:n.plotX,plotY:n.plotMACD,isNull:!g(n.plotMACD)}),g(n.plotSignal)&&r[1].push({plotX:n.plotX,plotY:n.plotSignal,isNull:!g(n.plotMACD)});["macd","signal"].forEach((e,s)=>{t.points=r[s],t.options=m(o[`${e}Line`]?.styles||{},i),t.graph=t[`graph${e}`],t.zones=(t[`${e}Zones`].zones||[]).slice(t[`${e}Zones`].startIndex||0),p().seriesTypes.sma.prototype.drawGraph.call(t),t[`graph${e}`]=t.graph}),t.points=e,t.options=o,t.zones=s}applyZones(){let t=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=t}getValues(t,e){let o=e.longPeriod-e.shortPeriod,s=[],i=[],r=[],n,l,a,h=0,c=[];if(!(t.xData.length<e.longPeriod+e.signalPeriod)){for(a=0,n=p().seriesTypes.ema.prototype.getValues(t,{period:e.shortPeriod,index:e.index}),l=p().seriesTypes.ema.prototype.getValues(t,{period:e.longPeriod,index:e.index}),n=n.values,l=l.values;a<=n.length;a++)g(l[a])&&g(l[a][1])&&g(n[a+o])&&g(n[a+o][0])&&s.push([n[a+o][0],0,null,n[a+o][1]-l[a][1]]);for(a=0;a<s.length;a++)i.push(s[a][0]),r.push([0,null,s[a][3]]);for(a=0,c=(c=p().seriesTypes.ema.prototype.getValues({xData:i,yData:r},{period:e.signalPeriod,index:2})).values;a<s.length;a++)s[a][0]>=c[0][0]&&(s[a][2]=c[h][1],r[a]=[0,c[h][1],s[a][3]],null===s[a][3]?(s[a][1]=0,r[a][0]=0):(s[a][1]=d(s[a][3]-c[h][1]),r[a][0]=d(s[a][3]-c[h][1])),h++);return{values:s,xData:i,yData:r}}}}C.defaultOptions=m(x.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(t,e){let o;for(o in t||(t={}),e)t[o]=e[o]}(C.prototype,{nameComponents:["longPeriod","shortPeriod","signalPeriod"],pointArrayMap:["y","signal","MACD"],parallelArrays:["x","y","signal","MACD"],pointValKey:"y",markerAttribs:f,getColumnMetrics:l().seriesTypes.column.prototype.getColumnMetrics,crispCol:l().seriesTypes.column.prototype.crispCol,drawPoints:l().seriesTypes.column.prototype.drawPoints}),p().registerSeriesType("macd",C);let P=l();return r.default})());