highcharts
Version:
JavaScript charting framework
14 lines • 5.7 kB
JavaScript
/**
* Highstock JS v12.6.0 (2026-04-13)
* @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";var t={};t.n=e=>{var o=e&&e.__esModule?()=>e.default:()=>e;return t.d(o,{a:o}),o},t.d=(e,o)=>{for(var r in o)t.o(o,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:o[r]})},t.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let o=e.default;var r=t.n(o);let n=e.default.SeriesRegistry;var l=t.n(n);let{doc:i,win:s}=r();function p(e,t){return e>1e14?e:parseFloat(e.toPrecision(t||14))}function c(e){return d(e)&&"number"==typeof e.nodeType}function a(e){return"number"==typeof e&&!isNaN(e)&&e<1/0&&e>-1/0}function u(e){let t=Object.prototype.toString.call(e);return"[object Array]"===t||"[object Array Iterator]"===t}function d(e,t){return!!e&&"object"==typeof e&&(!t||!u(e))}function h(e,...t){let o,r=[e,...t],n={},l=function(e,t){return"object"!=typeof e&&(e={}),f(t,function(o,r){if("__proto__"!==r&&"constructor"!==r){let n;!d(o,!0)||(n=o?.constructor,d(o,!0)&&!c(o)&&n?.name&&"Object"!==n.name)||c(o)?e[r]=t[r]:e[r]=l(e[r]||{},o)}}),e};!0===e&&(n=r[1],r=Array.prototype.slice.call(r,2));let i=r.length;for(o=0;o<i;o++)n=l(n,r[o]);return n}function f(e,t,o){for(let r in e)Object.hasOwnProperty.call(e,r)&&t.call(o||e[r],e[r],r,e)}Array.prototype.find;let{atr:y,sma:g}=l().seriesTypes;function x(e,t){return{index:t,close:e.getColumn("close")[t],x:e.getColumn("x")[t]}}class m extends g{init(){let e=this;super.init.apply(e,arguments);let t=function(e,t,o,n={}){let l="function"==typeof e&&e.prototype||e;Object.hasOwnProperty.call(l,"hcEvents")||(l.hcEvents={});let i=l.hcEvents;r().Point&&e instanceof r().Point&&e.series&&e.series.chart&&(e.series.chart.runTrackerClick=!0);let s=e.addEventListener;s&&s.call(e,t,o,!!r().supportsPassiveEvents&&{passive:void 0===n.passive?-1!==t.indexOf("touch"):n.passive,capture:!1}),i[t]||(i[t]=[]);let p={fn:o,order:"number"==typeof n.order?n.order:1/0};return i[t].push(p),i[t].sort((e,t)=>e.order-t.order),function(){!function(e,t,o){function r(t,o){let r=e.removeEventListener;r&&r.call(e,t,o,!1)}function n(o){let n,l;e.nodeName&&(t?(n={})[t]=!0:n=o,f(n,function(e,t){if(o[t])for(l=o[t].length;l--;)r(t,o[t][l].fn)}))}let l="function"==typeof e&&e.prototype||e;if(Object.hasOwnProperty.call(l,"hcEvents")){let e=l.hcEvents;if(t){let l=e[t]||[];o?(e[t]=l.filter(function(e){return o!==e.fn}),r(t,o)):(n(e),e[t]=[])}else n(e),delete l.hcEvents}}(e,t,o)}}(this.chart.constructor,"afterLinkSeries",()=>{if(e.options){let t=e.options;t.cropThreshold=e.linkedParent.options.cropThreshold-(t.params.period-1)}t()},{order:1})}drawGraph(){let e=this,t=e.options,o=e.linkedParent,r=o.getColumn("x"),n=o?o.points:[],l=e.points,i=e.graph,s=n.length-l.length,p=s>0?s:0,c={options:{gapSize:t.gapSize}},u={top:[],bottom:[],intersect:[]},d={top:{styles:{lineWidth:t.lineWidth,lineColor:t.fallingTrendColor||t.color,dashStyle:t.dashStyle}},bottom:{styles:{lineWidth:t.lineWidth,lineColor:t.risingTrendColor||t.color,dashStyle:t.dashStyle}},intersect:t.changeTrendLine},y,m,b,v,C,T,O,j,S,P=l.length;for(;P--;)y=l[P],m=l[P-1],b=n[P-1+p],v=n[P-2+p],C=n[P+p],T=n[P+p+1],O=y.options.color,j={x:y.x,plotX:y.plotX,plotY:y.plotY,isNull:!1},!v&&b&&a(r[b.index-1])&&(v=x(o,b.index-1)),!T&&C&&a(r[C.index+1])&&(T=x(o,C.index+1)),!b&&v&&a(r[v.index+1])?b=x(o,v.index+1):!b&&C&&a(r[C.index-1])&&(b=x(o,C.index-1)),y&&b&&C&&v&&y.x!==b.x&&(y.x===C.x?(v=b,b=C):y.x===v.x?(b=v,v={close:o.getColumn("close")[b.index-1],x:r[b.index-1]}):T&&y.x===T.x&&(b=T,v=C)),m&&v&&b?(S={x:m.x,plotX:m.plotX,plotY:m.plotY,isNull:!1},y.y>=b.close&&m.y>=v.close?(y.color=O||t.fallingTrendColor||t.color,u.top.push(j)):y.y<b.close&&m.y<v.close?(y.color=O||t.risingTrendColor||t.color,u.bottom.push(j)):(u.intersect.push(j),u.intersect.push(S),u.intersect.push(h(S,{isNull:!0})),y.y>=b.close&&m.y<v.close?(y.color=O||t.fallingTrendColor||t.color,m.color=O||t.risingTrendColor||t.color,u.top.push(j),u.top.push(h(S,{isNull:!0}))):y.y<b.close&&m.y>=v.close&&(y.color=O||t.risingTrendColor||t.color,m.color=O||t.fallingTrendColor||t.color,u.bottom.push(j),u.bottom.push(h(S,{isNull:!0}))))):b&&(y.y>=b.close?(y.color=O||t.fallingTrendColor||t.color,u.top.push(j)):(y.color=O||t.risingTrendColor||t.color,u.bottom.push(j)));f(u,function(t,o){e.points=t,e.options=h(d[o].styles,c),e.graph=e["graph"+o+"Line"],g.prototype.drawGraph.call(e),e["graph"+o+"Line"]=e.graph}),e.points=l,e.options=t,e.graph=i}getValues(e,t){let o=t.period,r=t.multiplier,n=e.xData,l=e.yData,i=[],s=[],c=[],a=0===o?0:o-1,d=[],h=[],f=[],g,x,m,b,v,C,T,O,j;if(!(n.length<=o)&&u(l[0])&&4===l[0].length&&!(o<0)){for(j=0,f=y.prototype.getValues.call(this,e,{period:o}).yData;j<f.length;j++)O=l[a+j],T=l[a+j-1]||[],b=d[j-1],v=h[j-1],C=c[j-1],0===j&&(b=v=C=0),g=p((O[1]+O[2])/2+r*f[j]),x=p((O[1]+O[2])/2-r*f[j]),g<b||T[3]>b?d[j]=g:d[j]=b,x>v||T[3]<v?h[j]=x:h[j]=v,C===b&&O[3]<d[j]||C===v&&O[3]<h[j]?m=d[j]:(C===b&&O[3]>d[j]||C===v&&O[3]>h[j])&&(m=h[j]),i.push([n[a+j],m]),s.push(n[a+j]),c.push(m);return{values:i,xData:s,yData:c}}}}m.defaultOptions=h(g.defaultOptions,{params:{index:void 0,multiplier:3,period:10},risingTrendColor:"#06b535",fallingTrendColor:"#f21313",changeTrendLine:{styles:{lineWidth:1,lineColor:"#333333",dashStyle:"LongDash"}}}),function(e,t){let o;for(o in e||(e={}),t)e[o]=t[o]}(m.prototype,{nameBase:"Supertrend",nameComponents:["multiplier","period"]}),l().registerSeriesType("supertrend",m);let b=r();export{b as default};