highcharts
Version:
JavaScript charting framework
14 lines • 4.95 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
*/function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o(e._Highcharts,e._Highcharts.SeriesRegistry):"function"==typeof define&&define.amd?define("highcharts/indicators/supertrend",["highcharts/highcharts"],function(e){return o(e,e.SeriesRegistry)}):"object"==typeof exports?exports["highcharts/indicators/supertrend"]=o(e._Highcharts,e._Highcharts.SeriesRegistry):e.Highcharts=o(e.Highcharts,e.Highcharts.SeriesRegistry)}("u"<typeof window?this:window,(e,o)=>(()=>{"use strict";var r={512(e){e.exports=o},944(o){o.exports=e}};let t={};function l(e){let o=t[e];if(void 0!==o)return o.exports;let i=t[e]={exports:{}};return r[e](i,i.exports,l),i.exports}l.n=e=>{let o=e&&e.__esModule?()=>e.default:()=>e;return l.d(o,{a:o}),o},l.d=(e,o)=>{if(Array.isArray(o))for(var r=0;r<o.length;){var t=o[r++],i=o[r++];l.o(e,t)?0===i&&r++:0===i?Object.defineProperty(e,t,{enumerable:!0,value:o[r++]}):Object.defineProperty(e,t,{enumerable:!0,get:i})}else for(var t in o)l.o(o,t)&&!l.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:o[t]})},l.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o);let i={};l.d(i,{default:()=>g});var s=l(944),n=l.n(s),a=l(512),p=l.n(a);let{atr:h,sma:c}=p().seriesTypes;function d(e,o){return{index:o,close:e.getColumn("close")[o],x:e.getColumn("x")[o]}}class u extends c{init(){let e=this;super.init.apply(e,arguments);let o=(0,s.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,r=e.linkedParent,t=r.getColumn("x"),l=r?r.points:[],i=e.points,n=e.graph,a=l.length-i.length,p=a>0?a: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,x,f,m,b,C,T,v,S,N=i.length;for(;N--;)y=i[N],x=i[N-1],f=l[N-1+p],m=l[N-2+p],b=l[N+p],C=l[N+p+1],T=y.options.color,v={x:y.x,plotX:y.plotX,plotY:y.plotY,isNull:!1},!m&&f&&(0,s.isNumber)(t[f.index-1])&&(m=d(r,f.index-1)),!C&&b&&(0,s.isNumber)(t[b.index+1])&&(C=d(r,b.index+1)),!f&&m&&(0,s.isNumber)(t[m.index+1])?f=d(r,m.index+1):!f&&b&&(0,s.isNumber)(t[b.index-1])&&(f=d(r,b.index-1)),y&&f&&b&&m&&y.x!==f.x&&(y.x===b.x?(m=f,f=b):y.x===m.x?(f=m,m={close:r.getColumn("close")[f.index-1],x:t[f.index-1]}):C&&y.x===C.x&&(f=C,m=b)),x&&m&&f?(S={x:x.x,plotX:x.plotX,plotY:x.plotY,isNull:!1},y.y>=f.close&&x.y>=m.close?(y.color=T||o.fallingTrendColor||o.color,u.top.push(v)):y.y<f.close&&x.y<m.close?(y.color=T||o.risingTrendColor||o.color,u.bottom.push(v)):(u.intersect.push(v),u.intersect.push(S),u.intersect.push((0,s.merge)(S,{isNull:!0})),y.y>=f.close&&x.y<m.close?(y.color=T||o.fallingTrendColor||o.color,x.color=T||o.risingTrendColor||o.color,u.top.push(v),u.top.push((0,s.merge)(S,{isNull:!0}))):y.y<f.close&&x.y>=m.close&&(y.color=T||o.risingTrendColor||o.color,x.color=T||o.fallingTrendColor||o.color,u.bottom.push(v),u.bottom.push((0,s.merge)(S,{isNull:!0}))))):f&&(y.y>=f.close?(y.color=T||o.fallingTrendColor||o.color,u.top.push(v)):(y.color=T||o.risingTrendColor||o.color,u.bottom.push(v)));(0,s.objectEach)(u,function(o,r){e.points=o,e.options=(0,s.merge)(g[r].styles,h),e.graph=e["graph"+r+"Line"],c.prototype.drawGraph.call(e),e["graph"+r+"Line"]=e.graph}),e.points=i,e.options=o,e.graph=n}getValues(e,o){let r=o.period,t=o.multiplier,l=e.xData,i=e.yData,n=[],a=[],p=[],c=0===r?0:r-1,d=[],u=[],g=[],y,x,f,m,b,C,T,v,S;if(!(l.length<=r)&&(0,s.isArray)(i[0])&&4===i[0].length&&!(r<0)){for(S=0,g=h.prototype.getValues.call(this,e,{period:r}).yData;S<g.length;S++)v=i[c+S],T=i[c+S-1]||[],m=d[S-1],b=u[S-1],C=p[S-1],0===S&&(m=b=C=0),y=(0,s.correctFloat)((v[1]+v[2])/2+t*g[S]),x=(0,s.correctFloat)((v[1]+v[2])/2-t*g[S]),y<m||T[3]>m?d[S]=y:d[S]=m,x>b||T[3]<b?u[S]=x:u[S]=b,C===m&&v[3]<d[S]||C===b&&v[3]<u[S]?f=d[S]:(C===m&&v[3]>d[S]||C===b&&v[3]>u[S])&&(f=u[S]),n.push([l[c+S],f]),a.push(l[c+S]),p.push(f);return{values:n,xData:a,yData:p}}}}u.defaultOptions=(0,s.merge)(c.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,s.extend)(u.prototype,{nameBase:"Supertrend",nameComponents:["multiplier","period"]}),p().registerSeriesType("supertrend",u);let g=n();return i.default})());