highcharts
Version:
JavaScript charting framework
14 lines • 5.75 kB
JavaScript
/**
* Highstock JS v12.6.0 (2026-04-13)
* @module highcharts/indicators/dmi
* @requires highcharts
* @requires highcharts/modules/stock
*
* Indicator series type for Highcharts Stock
*
* (c) 2010-2026 Highsoft AS
* Author: Rafał Sebestjański
*
* A commercial license may be required depending on use.
* See www.highcharts.com/license
*/import*as t from"../highcharts.js";var e,a={};a.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return a.d(e,{a:e}),e},a.d=(t,e)=>{for(var r in e)a.o(e,r)&&!a.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},a.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);let r=t.default;var o=a.n(r);let s=t.default.SeriesRegistry;var i=a.n(s);let{doc:n,win:l}=o();function p(t,e){return t>1e14?t:parseFloat(t.toPrecision(e||14))}function h(t){return u(t)&&"number"==typeof t.nodeType}function c(t){let e=Object.prototype.toString.call(t);return"[object Array]"===e||"[object Array Iterator]"===e}function u(t,e){return!!t&&"object"==typeof t&&(!e||!c(t))}function f(t,...e){let a,r=[t,...e],o={},s=function(t,e){return"object"!=typeof t&&(t={}),function(t,e,a){for(let a in t)Object.hasOwnProperty.call(t,a)&&e.call((0,t[a]),t[a],a,t)}(e,function(a,r){if("__proto__"!==r&&"constructor"!==r){let o;!u(a,!0)||(o=a?.constructor,u(a,!0)&&!h(a)&&o?.name&&"Object"!==o.name)||h(a)?t[r]=e[r]:t[r]=s(t[r]||{},a)}}),t};!0===t&&(o=r[1],r=Array.prototype.slice.call(r,2));let i=r.length;for(a=0;a<i;a++)o=s(o,r[a]);return o}Array.prototype.find;let{sma:{prototype:y}}=i().seriesTypes;!function(t){let e=["bottomLine"],a=["top","bottom"],o=["top"];function s(t){return"plot"+t.charAt(0).toUpperCase()+t.slice(1)}function i(t,e){let a=[];return(t.pointArrayMap||[]).forEach(t=>{t!==e&&a.push(s(t))}),a}function n(){let t=this,e=t.pointValKey,a=t.linesApiNames,o=t.areaLinesNames,n=t.points,l=t.options,p=t.graph,h={options:{gapSize:l.gapSize}},c=[],u=i(t,e),m=n.length,d;if(u.forEach((t,e)=>{for(c[e]=[];m--;)d=n[m],c[e].push({x:d.x,plotX:d.plotX,plotY:d[t],isNull:null==d[t]});m=n.length}),t.userOptions.fillColor&&o.length){let e=c[u.indexOf(s(o[0]))],a=1===o.length?n:c[u.indexOf(s(o[1]))],r=t.color;t.points=a,t.nextPoints=e,t.color=t.userOptions.fillColor,t.options=f(n,h),t.graph=t.area,t.fillGraph=!0,y.drawGraph.call(t),t.area=t.graph,delete t.nextPoints,delete t.fillGraph,t.color=r}a.forEach((e,a)=>{c[a]?(t.points=c[a],l[e]?t.options=f(l[e].styles,h):(0,r.error)('Error: "There is no '+e+' in DOCS options declared. Check if linesApiNames are consistent with your DOCS line names."'),t.graph=t["graph"+e],y.drawGraph.call(t),t["graph"+e]=t.graph):(0,r.error)('Error: "'+e+" doesn't have equivalent in pointArrayMap. To many elements in linesApiNames relative to pointArrayMap.\"")}),t.points=n,t.options=l,t.graph=p,y.drawGraph.call(t)}function l(t){let e,a=[],r=[];if(t=t||this.points,this.fillGraph&&this.nextPoints){if((e=y.getGraphPath.call(this,this.nextPoints))&&e.length){e[0][0]="L",a=y.getGraphPath.call(this,t),r=e.slice(0,a.length);for(let t=r.length-1;t>=0;t--)a.push(r[t])}}else a=y.getGraphPath.apply(this,arguments);return a}function p(t){let e=[];return(this.pointArrayMap||[]).forEach(a=>{e.push(t[a])}),e}function h(){let t=this.pointArrayMap,e=[],a;e=i(this),y.translate.apply(this,arguments),this.points.forEach(r=>{t.forEach((t,o)=>{a=r[t],this.dataModify&&(a=this.dataModify.modifyValue(a)),null!==a&&(r[e[o]]=this.yAxis.toPixels(a,!0))})})}t.compose=function(t){let r=t.prototype;return r.linesApiNames=r.linesApiNames||e.slice(),r.pointArrayMap=r.pointArrayMap||a.slice(),r.pointValKey=r.pointValKey||"top",r.areaLinesNames=r.areaLinesNames||o.slice(),r.drawGraph=n,r.getGraphPath=l,r.toYData=p,r.translate=h,t}}(e||(e={}));let m=e,{sma:d}=i().seriesTypes;class g extends d{calculateDM(t,e,a){let r=t[e][1],o=t[e][2],s=t[e-1][1],i=t[e-1][2];return p(r-s>i-o?a?Math.max(r-s,0):0:a?0:Math.max(i-o,0))}calculateDI(t,e){return t/e*100}calculateDX(t,e){return p(Math.abs(t-e)/Math.abs(t+e)*100)}smoothValues(t,e,a){return p(t-t/a+e)}getTR(t,e){return p(Math.max(t[1]-t[2],e?Math.abs(t[1]-e[3]):0,e?Math.abs(t[2]-e[3]):0))}getValues(t,e){let a=e.period,r=t.xData,o=t.yData,s=o?o.length:0,i=[],n=[],l=[];if(r.length<=a||!c(o[0])||4!==o[0].length)return;let p=0,h=0,u=0,f;for(f=1;f<s;f++){let t,e,s,c,y,m,d,g,D;f<=a?(c=this.calculateDM(o,f,!0),y=this.calculateDM(o,f),m=this.getTR(o[f],o[f-1]),p+=c,h+=y,u+=m,f===a&&(d=this.calculateDI(p,u),g=this.calculateDI(h,u),D=this.calculateDX(p,h),i.push([r[f],D,d,g]),n.push(r[f]),l.push([D,d,g]))):(c=this.calculateDM(o,f,!0),y=this.calculateDM(o,f),m=this.getTR(o[f],o[f-1]),t=this.smoothValues(p,c,a),e=this.smoothValues(h,y,a),s=this.smoothValues(u,m,a),p=t,h=e,u=s,d=this.calculateDI(p,u),g=this.calculateDI(h,u),D=this.calculateDX(p,h),i.push([r[f],D,d,g]),n.push(r[f]),l.push([D,d,g]))}return{values:i,xData:n,yData:l}}}g.defaultOptions=f(d.defaultOptions,{params:{index:void 0},marker:{enabled:!1},tooltip:{pointFormat:'<span style="color: {point.color}">●</span><b> {series.name}</b><br/><span style="color: {point.color}">DX</span>: {point.y}<br/><span style="color: {point.series.options.plusDILine.styles.lineColor}">+DI</span>: {point.plusDI}<br/><span style="color: {point.series.options.minusDILine.styles.lineColor}">-DI</span>: {point.minusDI}<br/>'},plusDILine:{styles:{lineWidth:1,lineColor:"#06b535"}},minusDILine:{styles:{lineWidth:1,lineColor:"#f21313"}},dataGrouping:{approximation:"averages"}}),function(t,e){let a;for(a in t||(t={}),e)t[a]=e[a]}(g.prototype,{areaLinesNames:[],nameBase:"DMI",linesApiNames:["plusDILine","minusDILine"],pointArrayMap:["y","plusDI","minusDI"],parallelArrays:["x","y","plusDI","minusDI"],pointValKey:"y"}),m.compose(g),i().registerSeriesType("dmi",g);let D=o();export{D as default};