highcharts
Version:
JavaScript charting framework
14 lines • 4.32 kB
JavaScript
/**
* Highstock JS v13.0.1 (2026-08-17)
* @module highcharts/indicators/supertrend
* @requires highcharts
* @requires highcharts/modules/stock
*
* Indicator series type for Highcharts Stock
*
* (c) 2010-2026 Highsoft AS
* Author: Wojciech Chmiel
*
* A commercial license may be required depending on use,
* see www.highcharts.com/license
*/import*as e from"../highcharts.js";let o={};o.n=e=>{let r=e&&e.__esModule?()=>e.default:()=>e;return o.d(r,{a:r}),r},o.d=(e,r)=>{if(Array.isArray(r))for(var t=0;t<r.length;){var l=r[t++],i=r[t++];o.o(e,l)?0===i&&t++:0===i?Object.defineProperty(e,l,{enumerable:!0,value:r[t++]}):Object.defineProperty(e,l,{enumerable:!0,get:i})}else for(var l in r)o.o(r,l)&&!o.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:r[l]})},o.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o);let r=e.default;var t=o.n(r);let l=e.default.SeriesRegistry;var i=o.n(l);let{atr:s,sma:n}=i().seriesTypes;function a(e,o){return{index:o,close:e.getColumn("close")[o],x:e.getColumn("x")[o]}}class p extends n{init(){let e=this;super.init.apply(e,arguments);let o=(0,r.addEvent)(this.chart.constructor,"afterLinkSeries",()=>{let{linkedParent:r,options:t}=e;t&&r&&(t.cropThreshold=(r.options.cropThreshold??0)-((t.params?.period??0)-1)),o()},{order:1})}drawGraph(){let e=this,o=e.options,t=e.linkedParent,l=t.getColumn("x"),i=t?t.points:[],s=e.points,p=e.graph,c=i.length-s.length,d=c>0?c:0,h={options:{gapSize:o.gapSize}},u={top:[],bottom:[],intersect:[]},g={top:{styles:{lineWidth:o.lineWidth,lineColor:o.fallingTrendColor||o.color,dashStyle:o.dashStyle}},bottom:{styles:{lineWidth:o.lineWidth,lineColor:o.risingTrendColor||o.color,dashStyle:o.dashStyle}},intersect:o.changeTrendLine},y,m,x,f,C,b,T,v,S,N=s.length;for(;N--;)y=s[N],m=s[N-1],x=i[N-1+d],f=i[N-2+d],C=i[N+d],b=i[N+d+1],T=y.options.color,v={x:y.x,plotX:y.plotX,plotY:y.plotY,isNull:!1},!f&&x&&(0,r.isNumber)(l[x.index-1])&&(f=a(t,x.index-1)),!b&&C&&(0,r.isNumber)(l[C.index+1])&&(b=a(t,C.index+1)),!x&&f&&(0,r.isNumber)(l[f.index+1])?x=a(t,f.index+1):!x&&C&&(0,r.isNumber)(l[C.index-1])&&(x=a(t,C.index-1)),y&&x&&C&&f&&y.x!==x.x&&(y.x===C.x?(f=x,x=C):y.x===f.x?(x=f,f={close:t.getColumn("close")[x.index-1],x:l[x.index-1]}):b&&y.x===b.x&&(x=b,f=C)),m&&f&&x?(S={x:m.x,plotX:m.plotX,plotY:m.plotY,isNull:!1},y.y>=x.close&&m.y>=f.close?(y.color=T||o.fallingTrendColor||o.color,u.top.push(v)):y.y<x.close&&m.y<f.close?(y.color=T||o.risingTrendColor||o.color,u.bottom.push(v)):(u.intersect.push(v),u.intersect.push(S),u.intersect.push((0,r.merge)(S,{isNull:!0})),y.y>=x.close&&m.y<f.close?(y.color=T||o.fallingTrendColor||o.color,m.color=T||o.risingTrendColor||o.color,u.top.push(v),u.top.push((0,r.merge)(S,{isNull:!0}))):y.y<x.close&&m.y>=f.close&&(y.color=T||o.risingTrendColor||o.color,m.color=T||o.fallingTrendColor||o.color,u.bottom.push(v),u.bottom.push((0,r.merge)(S,{isNull:!0}))))):x&&(y.y>=x.close?(y.color=T||o.fallingTrendColor||o.color,u.top.push(v)):(y.color=T||o.risingTrendColor||o.color,u.bottom.push(v)));(0,r.objectEach)(u,function(o,t){e.points=o,e.options=(0,r.merge)(g[t].styles,h),e.graph=e["graph"+t+"Line"],n.prototype.drawGraph.call(e),e["graph"+t+"Line"]=e.graph}),e.points=s,e.options=o,e.graph=p}getValues(e,o){let t=o.period,l=o.multiplier,i=e.xData,n=e.yData,a=[],p=[],c=[],d=0===t?0:t-1,h=[],u=[],g=[],y,m,x,f,C,b,T,v,S;if(!(i.length<=t)&&(0,r.isArray)(n[0])&&4===n[0].length&&!(t<0)){for(S=0,g=s.prototype.getValues.call(this,e,{period:t}).yData;S<g.length;S++)v=n[d+S],T=n[d+S-1]||[],f=h[S-1],C=u[S-1],b=c[S-1],0===S&&(f=C=b=0),y=(0,r.correctFloat)((v[1]+v[2])/2+l*g[S]),m=(0,r.correctFloat)((v[1]+v[2])/2-l*g[S]),y<f||T[3]>f?h[S]=y:h[S]=f,m>C||T[3]<C?u[S]=m:u[S]=C,b===f&&v[3]<h[S]||b===C&&v[3]<u[S]?x=h[S]:(b===f&&v[3]>h[S]||b===C&&v[3]>u[S])&&(x=u[S]),a.push([i[d+S],x]),p.push(i[d+S]),c.push(x);return{values:a,xData:p,yData:c}}}}p.defaultOptions=(0,r.merge)(n.defaultOptions,{params:{index:void 0,multiplier:3,period:10},risingTrendColor:"var(--highcharts-positive-color)",fallingTrendColor:"var(--highcharts-negative-color)",changeTrendLine:{styles:{lineWidth:1,lineColor:"var(--highcharts-neutral-color-80)",dashStyle:"LongDash"}}}),(0,r.extend)(p.prototype,{nameBase:"Supertrend",nameComponents:["multiplier","period"]}),i().registerSeriesType("supertrend",p);let c=t();export{c as default};